Databinding combobox to custom object - selected index / item not updating object property

I'm pulling my hair out trying to bind a custom object property to a combobox so that when the combox selecteditem is changed the value in the custom outject is updated  to reflect this change and the onPropertyChanged event occurs  - sorry if this is a really simple request:

 

Code:

object:

public class TeleconferencingInfo : INotifyPropertyChanged
{

private string test;

/// <summary>

///

/// </summary>

public string Test

{

get

{

return test;

}

set

{

test = value;

onPropertyChanged("Test");

}

 

private void onPropertyChanged(string propertyName)

{

if (PropertyChanged == null)

return;

PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

}

public event PropertyChangedEventHandler PropertyChanged;

}

 

}

attempt at databinding:

 

TeleconferencingInfo _TeleconferencingInfo = new TeleconferencingInfo();

 

comboBox1.DataBindings.Add("SelectedValue", _TeleconferencingInfo, "Test");

 comboBox - items - strings "1", "2" "3" etc

any help much appreciated.

 

mit99mhAsked:
Who is Participating?
 
mit99mhConnect With a Mentor Author Commented:
I found a solution:

BindingSource teleconferencingBindingSource = new BindingSource();
teleconferencingBindingSource.DataSource = _TeleconferencingInfo;

myComboBox.DataBindings.Add("SelectedValue", teleconferencingBindingSource, "Test", true, DataSourceUpdateMode.OnPropertyChanged);
0
 
CoyotesITCommented:
Is the control set to "AutoPostBack" = true?
0
 
p_davisCommented:
you might want to give you private test an instantiating value like null or string.empty.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.