May 12, 2009
If you want to capture changes in ComboBox you can use ‘SelectedIndexChanged’ or ‘SelectedValueChanged’ events. However, if you want to get changes only when the user changes the selection, use ‘SelectionChangeCommitted’ event instead.
SelectionChangeCommitted occurs only when the ComboBox selection changes by user (via keyboard or mouse) and it is not raised when the selection changes programmatically.
Leave a Comment » |
Uncategorized | Tagged: ComboBox |
Permalink
Posted by SkilledDeveloper
February 3, 2009
Problem:
When you want to use a data bound ComboBox in .NET (C#, VB, etc), you should set a few properties such as DataSource, DisplayMember and ValueMember.
It works fine unless you want to set SelectedValue for the first time. It won’t be set.
Solution:
I found that BindingContext property must be used before initializing SelectedValue:
ComboBox1.BindingContext = new BindingContext();
ComboBox1.DataSource = MyDataSet.DefaultView
ComboBox1.DisplayMember = “Title”;
ComboBox1.ValueMember = “Code”;
ComboBox1.SelectedValue = 1;
2 Comments |
Problems and Solutions | Tagged: BindingContext, ComboBox, DisplayMember, SelectedValue, ValueMember |
Permalink
Posted by SkilledDeveloper