trouble with DataBinding (Master/Details)

A

Adik

Hi,

I've got a problem with the DataBindings. I've got a form with 3
textboxes and also one DataGrid which shows the details for the the
current record.

I've got a DataSet with two tables in it (Master/Details). I created
primary keys and set a relation between those two tables. In Addition
i bound the three textboxes to the master-table.

My problem is: If i now want to change the current record using the
BindingContext it only works for the textboxes but my DataGrid still
shows the first record which was loaded when the form loaded :-(

Please check my code before i get sick of this problem...


public void addproducts()
{
OleDbCommand SelCom = new OleDbCommand("Select * from
tab_products", con.getCon());
productsadapter.SelectCommand = selCom;
OleDbCommand selDetails = new OleDbCommand("Select * from
tab_prices", con.getCon());
detailsadapter.SelectCommand = selDetails;
productsadapter.Fill(ds, "tab_products");
detailsadapter.Fill(ds,"tab_prices");
ds.Relation.Add("productdetails",ds.Tables["tab_products"].Columns["PRD_Nr",
ds.Tables["tab_prices"].Columns["ARP_PRDNr"]);
dgd_details.DataSource = ds;
dgd_details.DataMember = "tab_prices.productdetails";
this.txt_nr.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_Nr");
this.txt_description.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_Description");
this.txt_info.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_Info");

this.BindingContext[ds.Tables["tab_products"]].Position
= 5;
}


Thanks for u support!

Christoph

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
A

Adik

If i change it the DataGrid doesnt show the details anymore...let me
make it clear. There is one table in the Database with the product
number, the description and an info...and there is another table with
the number of the one who can deliver the product and the price...so
for each product there can be many details and thats what the
datagrid should show...and it works! The only Problem is that if i
change the record by using the command


this.BindingContext[ds.Tables["tab_products"]].Position
= 5;


it has only affect to the textboxes but not to the DataGrid which
shows the details :-(

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Y

yonggangwang

Hi:
You can use DataView to solve your problem, I have already tried;

System.Data.DataView dvDetail = new Syetem.Data.DataView();
dvDetail.Table=ds.Tables("tab_prices");
dvDetail.RowFilter=("ARP_PRDNr=" + txt_nr.text);
dgd_details.DataSource=dvDetail;
dgd_details.DataMember = "tab_prices.productdetails";





Adik said:
Hi,

I've got a problem with the DataBindings. I've got a form with 3
textboxes and also one DataGrid which shows the details for the the
current record.

I've got a DataSet with two tables in it (Master/Details). I created
primary keys and set a relation between those two tables. In Addition
i bound the three textboxes to the master-table.

My problem is: If i now want to change the current record using the
BindingContext it only works for the textboxes but my DataGrid still
shows the first record which was loaded when the form loaded :-(

Please check my code before i get sick of this problem...


public void addproducts()
{
OleDbCommand SelCom = new OleDbCommand("Select * from
tab_products", con.getCon());
productsadapter.SelectCommand = selCom;
OleDbCommand selDetails = new OleDbCommand("Select * from
tab_prices", con.getCon());
detailsadapter.SelectCommand = selDetails;
productsadapter.Fill(ds, "tab_products");
detailsadapter.Fill(ds,"tab_prices");
ds.Relation.Add("productdetails",ds.Tables["tab_products"].Columns["PRD_Nr",
ds.Tables["tab_prices"].Columns["ARP_PRDNr"]);
dgd_details.DataSource = ds;
dgd_details.DataMember = "tab_prices.productdetails";
this.txt_nr.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_Nr");
this.txt_description.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_D
escription");this.txt_info.DataBindings.Add("text,ds.Tables["tab_products"],"PRD_Info");

this.BindingContext[ds.Tables["tab_products"]].Position
= 5;
}


Thanks for u support!

Christoph

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Top