views:

82

answers:

1

Heya,

I want to create a winforms app where you can assign tags to an entity. ofc I want the customer to re-use existing tags a lot. That's why I want to show them the list of tags while they are typing (similar to intellisense in VS and the tags-dropdown even here in stackoverflow ;))

  • do you have any control(s) in mind that offers this functionality?
  • can I reuse a ComboBox for this? (here I need to drop it down programatically - how?)

I want to have the taglist getting input-focus but not lose the mainform-focus, and I want it to be on top over all windows and even range out of the mainform-area (like intellisense in vs)

thx!

+1  A: 

Here I have made a function to which pass the table name from which auto-complete has to be done, name of the field which needs to be auto-complete and the combobox which needs to be targeted.

Try the following code:

public void AutoCompleteTextBox(string tableName, string fieldName, ComboBox combToAutoComp)
        {
            AutoCompleteStringCollection txtCollection = new AutoCompleteStringCollection();
            DataTable dtAutoComp = Dal.ExecuteDataSetBySelect("Stored_Procedure", fieldName, tableName);
            if (dtAutoComp.Rows.Count >= 0)
            {
                for (int count = 0; count < dtAutoComp.Rows.Count; count++)
                {
                    txtCollection.Add(dtAutoComp.Rows[count][fieldName].ToString());
                }
            }
            combToAutoComp.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            combToAutoComp.AutoCompleteSource = AutoCompleteSource.CustomSource;
            combToAutoComp.AutoCompleteCustomSource = txtCollection;
        }

Here Dal.ExecuteDataSetBySelect is my implementation where i create the connection, command and dataadapter for calling the stored-procedure. You can replace it with your own implementation for the same. For more refer this link

HotTester
thx buddy, worked sufficiently. though i decided after many more struggles to take the steeper learning curve of WPF and started from scratch with my project using WPF - wish me luck :)
Sargola
All the best :)
HotTester