ContextMenuStrip - DataBinding to one of the items

G

Guest

I'm trying to do basic data binding to a ToolStripComboBox but the
items aren't being populated. If i put a break point i can see that
the data source has information in it but it's not being displayed. So
the DataSource does have the BindingList associated with it. This is for a
ContextMenuStrip; a toolstrip seems to work ok.

private BindingList<string> _binding = new BindingList<string>(new
string[] { "Hello", "Goodbye" });

protected override void OnLoad(...) {
// i also tried going tdirectly to toolStripComboBox1.ComboBox
ComboBox cBox = toolStripComboBox1.Control as ComboBox;
toolStripComboBox1.Sorted = false;
cBox.Sorted = false;

cBox.DataSource = _binding;
this._cbo2.ComboBox.DataSource = _binding;
comboBox1.DataSource = _binding;


}

Googlin', the only thing i can find is a mention that if the data
source is an array, and you try to sort the combo box, it will cause
the items not to display. So i set the sorted properties to false for
the hell of it.


The only way i got it to work was to add the control to the form's/user
control's control collection, do the data bindnig, then add it to a
ToolStripControlHost. If i don't perform that step it doesn't work. The
problem with this approach is that when i add new items to the binding list
it won't update the combobox(or listbox) even if i call refresh on the
currency manager or call ResetBindings on the BindingList.

Am i doing something completely stupid here?
 
B

Bart Mermuys

Hi,

cisco said:
I'm trying to do basic data binding to a ToolStripComboBox but the
items aren't being populated. If i put a break point i can see that
the data source has information in it but it's not being displayed. So
the DataSource does have the BindingList associated with it. This is for a
ContextMenuStrip; a toolstrip seems to work ok.
private BindingList<string> _binding = new BindingList<string>(new
string[] { "Hello", "Goodbye" });

Try explicitly setting a BindingContext first:

toolStripComboBox1.ComboBox.BindingContext = this.BindingContext;

I would also put a BindingSource inbetween:

toolStripComboBox1.ComboBox.DataSource = new BindingSource(_binding, "");


HTH,
Greetings
 
G

Guest

Bart,

Ahh that makes sense. The binding context was switched! argg! my head
hurts ;)

I really apprecite the help!

Cisco

Bart Mermuys said:
Hi,

cisco said:
I'm trying to do basic data binding to a ToolStripComboBox but the
items aren't being populated. If i put a break point i can see that
the data source has information in it but it's not being displayed. So
the DataSource does have the BindingList associated with it. This is for a
ContextMenuStrip; a toolstrip seems to work ok.
private BindingList<string> _binding = new BindingList<string>(new
string[] { "Hello", "Goodbye" });

Try explicitly setting a BindingContext first:

toolStripComboBox1.ComboBox.BindingContext = this.BindingContext;

I would also put a BindingSource inbetween:

toolStripComboBox1.ComboBox.DataSource = new BindingSource(_binding, "");


HTH,
Greetings
 

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