• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 943
  • Last Modified:

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.

 

0
mit99mh
Asked:
mit99mh
1 Solution
 
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
 
mit99mhAuthor Commented:
I found a solution:

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

myComboBox.DataBindings.Add("SelectedValue", teleconferencingBindingSource, "Test", true, DataSourceUpdateMode.OnPropertyChanged);
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now