edit datatable record with textbox

jsn1

Member
Joined
Jul 14, 2006
Messages
12
Programming Experience
10+
hi all,

I created the datatable, and bound it to a datagrid and several textboxes. In my windows form I have a tabControl with two tabs:
- one for the list, with a datagrid that displays the content of the datatable,
- another tab called "detail" that displays the record selected on the datagrid. Here the user can modify a text box. And I would like to save the modification in the datatable. Otherwise when the user switches between the tabs "List" and "Details", the modifications entered in the text box are not visible in the datagrid.


Probably I am missing the "
Me.BindingContext()"

I do not know how this BindingContext works.


As a short example lets say that I have the following datatable:

DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add("foo");
dt.Rows.Add("dsnv");
dt.Rows.Add("nv");
dt.Rows.Add(new object[] { null });
dt.Rows.Add(DBNull.Value);

Binding b = new Binding("Text", dt, "Name", true);
b.NullValue = "nv";
this.textBox1.DataBindings.Add(b);


Because the textbox in binded to the datatable, if I modify the value ot the textbox1. What do I have to to to save the new value on the datatable.

thanks
jsn
 
That example won't work in vb.net because it's C#. You can add bindings a bit easier in the designer. Click on the textbox goto the data section and set the binding in there. As i said in your other thread, once the textbox is bound the changes will be automatically reflected in datatable.
 
Hi,

the text box is already bound, and my question is: why I do not see the modified fields in the datagrid that points exactly to the same record as the text box. Do I need to refresh the datagrid

thanks
jsn
 
hi,

a combo box is bound like that:
'
' bind combobox
'

Me.cbDetailStatus.DataBindings.Add("SelectedValue", dtAASIS, "Status")

and I bound it as a text box, so it was wrong, this is why I could no see the modifications

jsn
 
Last edited:
Back
Top