Is it possible to have several list boxes control a data grid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 list boxes and a combo box that are bound to table adaptors. I have
another table that has relations with the underlying tables to the adaptors
above. I have set this up in a dataset. How do I get to this relationship
so I can bind a data grid to it? If I have only one list box and a grid, it
is provided by intelligence-sense. Is it possible to have several list
boxes/combo boxes and control a gird? I am using NET 2.0. Has any one done
this, or know how to do it, or where I can get some help?
Thank you,
 
Hi

Do you have a strongly typed dataset?
If so, you can add a DataRelation to your dataset that specifies the
relationship between the two tables. Then, in your data grid, instead
of databinding to a table, databind to that datarelation instead. Make
sure that your combo is bound to the first table as well.
..NET takes care of the rest. :)
 
Hi Mike,

Thank you for posting.

You could use BindingSource and DataRelation between the DataTables in a
DataSet to build a master/detail application.

Here is a sample for you.

Suppose there're a DataSet (e.g DataSet1) containing two DataTables(e.g
State and City). I create a data relation called State_City between the
StateID column in State and the StateID column in City.

I drag&drop a ListBox, a ComboBox and a DataGridView onto a form. I'd like
to display the data of the State table in the ListBox and ComboBox , and
the corresponding data of the City table in the DataGridView.

Below is the code snippet.

private void Form1_Load(object sender, EventArgs e)
{
BindingSource bindingSource1 = new BindingSource();
BindingSource bindingSource2 = new BindingSource();

bindingSource1.DataMember = "State";
bindingSource1.DataSource = this.dataSet11;

bindingSource2.DataMember = "State_City";
bindingSource2.DataSource = bindingSource1;

this.listBox1.DataSource = bindingSource1;
this.listBox1.DisplayMember = "StateName";

this.comboBox1.DataSource = bindingSource1;
this.comboBox1.DisplayMember = "StateName";

this.dataGridView2.DataSource = bindingSource2;
}

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

============================================================================
=============================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.

============================================================================
=============================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Back
Top