Force update of Databinding

  • Thread starter Johnny Jörgensen
  • Start date
J

Johnny Jörgensen

I've got a combobox where the SelectedValue property is bound to a class
property by a code like this:

MyComboBox.DataBindings.Add("SelectedValue", MyClass , "MyID");

My problem is that the MyClass.MyID property gets updated when the focus
leaves the combobox - not when you actually select a new item from the drdop
down list.

I would have expected this code to solve the problem, but it didn't:
MyComboBox.DataBindings.DefaultDataSourceUpdateMode =
DataSourceUpdateMode.OnPropertyChanged;

I would do a work around and do a method in my class called UpdateMyID(long
MyIDValue) and call it from the MyComboBox_SelectedItemChanged event (which
is fired correctly), but the drop down list in the combo is data bound with
a ValueMember which is the ID in long format and a DisplayMember which is
the Value in string format, and I can't figure out how to get the
ValueMember from the SelectedItem and use it in calling my method. There is
apparently no SelectedItem.ValueMember property, and as far as I can see in
the intellisense no way of getting the ValueMember property

The best would be if I could programmatically for the databinding to update,
but there is no

MyComboBox.DataBindings.Refresh

method either.

Any suggestions as to how I can solve it?



Cheers,

Johnny J.
 
J

Johnny Jörgensen

I found another way to skin the cat, so please forget this post.

Cheers,
Johnny J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top