textbox databind problem

  • Thread starter Thread starter Oka Morikawa
  • Start date Start date
O

Oka Morikawa

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
 
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
 
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();

Rajesh Patel said:
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


Oka Morikawa said:
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
 
Back
Top