all groups > dotnet windows forms databinding > january 2005 >
You're in the

dotnet windows forms databinding

group:

Change notifications and combo box


Change notifications and combo box kh
1/17/2005 6:15:02 AM
dotnet windows forms databinding: Hi. I am binding a collection of objects to a combo box and have set the
DisplayMember to a property of the child objects. This is working fine.

However if the property is changed in code the text in the combo box is not
updated to reflect the change. I have added a property changed event to the
child class. Any ideas why this isn't working?

Thanks

kh
RE: Change notifications and combo box kh
1/18/2005 1:09:03 AM
Jeffrey

Many thanks. Works perfectly.

kh



[quoted text, click to view]
RE: Change notifications and combo box v-jetan NO[at]SPAM online.microsoft.com (
1/18/2005 6:32:45 AM
Hi kh,

Based on my understanding, you want to update the combobox after the bound
datasource of combobox is changed programmatically.

We may just get the currencymanager of combobox, then call its Update
method to force the re-bound, sample code like this:
public enum CustomColor
{
white=0,
red=1,
yellow=2,
blue=3
};

public class TestClass
{
private CustomColor _testprop=CustomColor.white;
public CustomColor testprop
{
get
{
return _testprop;
}
set
{
_testprop=value;
}
}
}

TestClass [] arr;
private void button1_Click(object sender, System.EventArgs e)
{
arr=new TestClass[4];
for(int i=0;i<4;i++)
{
arr[i]=new TestClass();
arr[i].testprop=(CustomColor)Enum.Parse(typeof(CustomColor),
Enum.GetName(typeof(CustomColor), i));
}
this.comboBox1.DataSource=arr;
this.comboBox1.ValueMember="testprop";
this.comboBox1.DisplayMember="testprop";
}

private void button2_Click(object sender, System.EventArgs e)
{
this.arr[0].testprop=CustomColor.yellow;
CurrencyManager cm=this.comboBox1.BindingContext[this.arr, ""] as
CurrencyManager;
cm.Refresh();
}
It works well on my side. Hope it helps.
================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
RE: Change notifications and combo box v-jetan NO[at]SPAM online.microsoft.com (
1/18/2005 9:36:46 AM
You are welcome!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button