I have DataSet with two DataTable and DataRelation between them.
I have two DataGrids with master / detail style and additional textbox which
are bind to detail table.
ds.Tables.Add(tableCompany);
ds.Tables.Add(tableBranch);
ds.Relations.Add("Branch",
ds.Tables["Company"].Columns["CompanyID"],
ds.Tables["Branch"].Columns["CompanyID"]);
this.gridCompany.SetDataBinding(ds.Tables["Company"], "");
this.gridBranch.SetDataBinding(ds.Tables["Company"], "Branch");
this.tbCode.DataBindings.Add("Text", ds.Tables["Company"], "Branch.Code");
this.tbStreet.DataBindings.Add("Text", ds.Tables["Company"],
"Branch.Street");
Now if I update textbox tbCode of tbStreet and then click the update button
which updates DT changes back to database nothing happens BUT if I after
updating TextBox click the DG then it will update changes back to DB.
How do I make so that the TextBox will update the DT immediately it loses
focus? Do I need to use some refreshing code on TextBox.Leave event? Or some
additional code on my Update button?
Thanks,
Oka Morikawa
Rajesh Patel - 04 Mar 2004 01:40 GMT
on your update button click add following code, before you call update on
database.
vb.net syntax
me.bindingcontext(ds.tables("company"), "").endcurrentedit()
c# syntax
this.bindingcontext(ds.tables["Company"], "").endcurrentedit()
Syntax may not be exact. you might need to change little bit.
The purpose is, your record is in edit mode, so take it out from edit mode
by calling endcurrentedit method.
hope this helps,
Rajesh Patel
> I have DataSet with two DataTable and DataRelation between them.
> I have two DataGrids with master / detail style and additional textbox which
[quoted text clipped - 23 lines]
> Thanks,
> Oka Morikawa
Oka Morikawa - 04 Mar 2004 11:36 GMT
Great!
Thought syntax didn't work but it was easy to figure out and my final
solution was:
BindingManagerBase xCurrent =
(CurrencyManager) BindingContext[ds.Tables["Company"], ""];
xCurrent.EndCurrentEdit();
> on your update button click add following code, before you call update on
> database.
[quoted text clipped - 44 lines]
> > Thanks,
> > Oka Morikawa