ComboBox Items Empty but DataSource Full

前端 未结 3 1343
梦谈多话
梦谈多话 2021-02-19 07:14

After binding a list to combobox, its dataSource.Count is 5 but, combobox item count is 0. how can it be?

I\'m used to Web programming and this is in Windows Forms. So

相关标签:
3条回答
  • 2021-02-19 07:43

    If you'd expand DataSource items in debuger, you'd probably notice that 1st element on list is null. That is why DataSource does not render ComboBox Items. Removing null items from the list should do all the work;

    0 讨论(0)
  • 2021-02-19 07:57

    I had the same problem, but in my case it was caused by calling

    combobox.Sorted = True
    

    in InitializeComponent. I guess that call initializes Items, which then prevents the assignment to DataSource from updating it (Items).

    0 讨论(0)
  • 2021-02-19 08:03

    After adding ddl.BindingContext = new BindingContext(); before the BindingSource assignment, everything worked fine.

    0 讨论(0)
提交回复
热议问题