I wanted to create binding dynamically and set this binding to a string object that was created on-the-fly and bind this to the displaymemberpathproperty of a combo box.
How do I go about doing this?
Here is my code so far but doesn't seem to work. What will I be setting the path property of the binding to (i.e. the reason i'm doing it this way is cause I have number of combo boxes that are using this one method):
private void ComboValue_DropDownClosed(object sender, EventArgs e)
{
ComboBox combo = (ComboBox)sender;
int selectedItemCount = 0;
foreach (MyItem item in combo.Items)
{
if (item.IsSelected == true)
selectedItemCount = selectedItemCount + 1;
}
string SelectedComboCount = selectedItemCount.ToString();
Binding b = new Binding();
b.Source = SelectedComboCount ;
combo.SetBinding(ComboBox.DisplayMemberPathProperty, b);
}