Archive | May, 2009


16 May

There are several ways to sort data in C# but one of the easiest ways is using BindingSource sort capability.
Depending on what object (underlying list) is linked to the BindingSource as its DataSource and whether it has implemented IBindingList or IBindingListView interfaces or not, you can use this feature.

To find out whether a BindingSource with current DataSource supports sorting, use ‘SupportsSorting’ property:

if (bindingSource1.SupportsSorting)
	bindingSource1.Sort = "Code, Name";

Similarly, you can benefit from BindingSource.Filter .

Using SelectionChangeCommitted event of ComboBox

12 May

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.

private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
    if (comboBox1.SelectedIndex == 1)
        //do something...
%d bloggers like this: