0
votes

I have been trying to get this to work and can not find why it will not. I have a loading form first which initializes everything then that form closes and the login form shows. The textbox for the username is supposed to get autocomplete values from config file. I can get all the values and it shows in the autocompletecustomsource but when I test it the textbox does not even show suggestions as I type. Here is the code I use to add all the form elements to the form. I have tried putting it in the onload overide as well as the initialization method.

[STAThread]
private void AddControls()
    {
        Label lb;
        TextBox tb;
        Button btn;

        lb = new Label()
        {
            AutoSize = true,
            Left = 5,
            Top = 5,
            Text = "Username:",
            Font = new Font(this.Font.FontFamily, 7, FontStyle.Italic)
        };
        this.Controls.Add(lb);
        tb = new TextBox()
        {
            Left = lb.Left,
            Top = lb.Bottom + 2,
            Width = this.Width - 10,
            Name = "user"
        };

        this.Controls.Add(tb);
        AutoCompleteStringCollection ASC = new AutoCompleteStringCollection();
        ASC.AddRange(_DataHandler.CFManager.GetConfigValue(BPConfig.CFGVal.Users).Split(';'));
        tb.AutoCompleteMode = AutoCompleteMode.Suggest;
        tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
        tb.AutoCompleteCustomSource = ASC;
    }
1
Have you checked the actual content of your AutoCompleteStringCollection? Assign the collection to another array before passing it to the collection, so you can better verify what's in it (possibly, trailing spaces and/or empty lines). - Jimi
Yes I did that. I verified there were no extra spaces or anything - JW12689
You understand that what your _DataHandler.CFManager.GetConfigValue() is returning is known to you only. If I pass a simple array of strings to the AutoCompleteStringCollection using the same code you posted here, it works as expected. - Jimi
I had the same problem with textbox, for me i was using multiline with textbox which was causing this issue. Changing multiline to false solved the issue. - Huzaifa

1 Answers

0
votes

Use ComboBox Like TextBox => comboBox1.DropDownStyle = ComboBoxStyle.Simple

var list = new List<string>() { ... };

comboBox1.DataSource = list;
comboBox1.DropDownStyle = ComboBoxStyle.Simple;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;