none
Combobox autocomplete does not work properly RRS feed

  • Question

  • I am adding combobox in Excel worksheet in C# VSTO project.

    I have tried the below code:

                ComboBox comboBox1 = new ComboBox();
                comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
                string txt = "book ";
                for (int i = 0; i < 200; i++)
                {
                    comboBox1.Items.Add(txt + "_" + i);
                }
                Microsoft.Office.Tools.Excel.Worksheet vstoSheet =
                              Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets[1]);

                Range ValidateCell = vstoSheet.Range["A1"];
                vstoSheet.Controls.AddControl(comboBox1, ValidateCell.Left, ValidateCell.Top, 600, 26, "customDD");

    Problem is that when I set AutoCompleteMode to AutoCompleteMode.Suggest, scrolling is not working on combobox items and correct item is not selected after clicking on the combobox item.

    If anyone has solution, please let me know.

    Wednesday, July 11, 2018 10:38 AM

All replies

  • Hello Saurabh Singh Jadon,

    Is the combobox  a Windows.Form.Combobox?

    If not, What's the combobox control? 

    In my test, I tried your code using a windows form control. It works for me to scroll the control and select the combobox. What's the version of your office? Could your reproduce the issue on other PC? If you put the control on a windows form application, will the issue still exist?

    Besides, I would suggest you insert an Excel Combobox control instead of a windows form combobox control to the worksheet. Do you have any necessary to use a windows form control?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 12, 2018 8:07 AM
  • Yes Terry, I am using windows form combobox. I am facing same problem with windows form application.

    If I remove the code comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;, it will work perfectly but I need this feature.

    I am using Excel 2013 V-15.0.5041.1000 and this problem also occurs on other machines.

    Monday, July 16, 2018 11:43 AM