C# 2.0 DataBinding using the BindingSource in user controls

R

Rajat

Hi,

I have a user control B put inside the parent user control A.

On the child control B, I have put a combo box and a BindingSource BS1. In
the load event of child control B, I fetch the
values from the database and put in a generic BindingList of NameValueClass.
(given below)


class NameValueClass
{

private int _id;
public int Id
{
get{return _id;}
set{_id = value;}
}


private string _name;
public int Id
{
get{return _name;}
set{_name = value;}
}

}

BindingList<NameValueClass> list = RetrieveComboValuesFromDataBase();

Next I assign the list to datasource of BindingSource BS1 (given below)


BS1.DataSource = list;

combo.DataSource = BS1;
combo.DataMember = "Name";
combo.ValueMember = "Id" ;

I have put a Grid on Parent control A. Now I want to show some detail data
on grid, On changing the combo box value i.e. As soon as the
value in the combo box is changed, I need to fetch corresponding details
from database and display on grid. What is the best
way to achieve the same using the BindingSource.

Regards,
Rajat.
 

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