How to bind ComboBoxItem or ComboBoxEx to Dictionary
Categories: DotNetBar for Windows Forms, How To
VB:
Dim dict = New Dictionary(Of String, String)() For n As Integer = 0 To 10 dict.Add("Key " + n.ToString(), "Value " + n.ToString()) Next ComboBoxItem1.ComboBoxEx.DataSource = New BindingSource(dict, Nothing) ComboBoxItem1.ComboBoxEx.DisplayMember = "Value" ComboBoxItem1.ComboBoxEx.ValueMember = "Key"
C#:
Dictionary<string, string> dict = new Dictionary<string, string>(); for (int n = 0; n <= 10; n++) { dict.Add("Key " + n.ToString(), "Value " + n.ToString()); } ComboBoxItem1.ComboBoxEx.DataSource = new BindingSource(dict, null); ComboBoxItem1.ComboBoxEx.DisplayMember = "Value"; ComboBoxItem1.ComboBoxEx.ValueMember = "Key";
Related posts:
Leave a Reply!