.Net Listbox DataBinding Problem

.Net Listbox DataBinding Problem

I have a main class which creates and populates a DataSet and an instance of this class is then passed to sub controls of my application by reference. I want to use this dataset to databind to components, in this case, a listbox. This is for a windows forms application.

Heres what I'm trying:

channelTypesLB.DataBindings.Add("Text", synData.ds, "ChannelTypes.channelType"); 

Note, I've also tried this: (not sure if theres a difference)

channelTypesLB.DataBindings.Add("Text", synData.ds.Tables["ChannelTypes"], "channelType"); 

Theres no errors and I do not see the data in the listbox... when I output synData.ds.Tables["ChannelTypes"].Rows.Count it tells me that there is in fact data in this datatable.

Am I missing something? I also trued channelTypesLB.Refresh(); after setting the databinding.

This may also be helpful... this is the code in my main class where the dataset is created, not sure if its maybe a scope issue, I'd imagine I would have received an error:

private DataSet _ds = new DataSet(); public DataSet ds { get { return _ds; } } 

WPF ListView Thousand Separator


WPF Data Triggers Set Object properties based on events
Try setting the Listbox's DataSource rather than binding to the Text property:.
(WPF) Binding two classes to a control
channelTypesLB.DataSource = synData.ds; channelTypesLB.DisplayMember = "ChannelTypes.channelType"; 
I'm not a DataBinding expert by any means, but I believe that by databinding the way you're currently doing it the control is binding to a PropertyManager which is used to bind one value of an object to one value of another.

Which User Control event comes between data binding (other controls) and Render?
By setting the DataSource it should bind to a CurrencyManager which is used to bind to a Collection..
DropDownList SelectedValue not binding properly
Here's a quick overview of WinForms databinding.
Binding DataGridView to a List<>, some properties Should not be shown

Is there a non-iterating control that allows data-binding syntax to be used?

How to bind DataGridView with List<T> or BindingList<T>


I'm assuming winforms here since there is no ASP.NET tag....
channelTypesLB.DataSource = synData.ds.Tables["ChannelTypes"].DefaultView; channelTypesLB.DisplayMember = "channelType"; 
Just in case it is ASP.NET though try:.
channelTypesLB.DataSource = synData.ds.Tables["ChannelTypes"].DefaultView; channelTypesLB.DataTextField = "channelType"; channelTypesLB.DataValueField = "channelTypeId"; // I'm assuming this field exists, replace with your id field  channelTypesLB.DataBind(); 

75 out of 100 based on 75 user ratings 375 reviews