Click to See Complete Forum and Search --> : [RESOLVED] Binding textbox to datagridview
Beast777
Oct 1st, 2007, 12:30 PM
I have created a dataset and a bindingsource. I set the datagridview datasource to the bindingsource and do the same for the textbox. As I move through my datagridviews rows, the textbox follows along nicely. When I edit the textbox or datagrid, the change will only show up once I change rows. My problem is if I edit the textbox and click on my save button which does this:
this.Validate();
this.persDataBindingSource.EndEdit();
this.persDataTableAdapter.Update(this.dsDocs.PersData);
It does not actually save the change because the dataset has not changed yet. How do I get this to work?
jmcilhinney
Oct 1st, 2007, 06:19 PM
I would have thought that that code would have pushed the new value to the data source before saving, but if it doesn't you can try calling the WriteValue method of the TextBox's Binding:this.textBox1.Bindings["Text"].WriteValue();That will force the value in the control to be written to the data source. It should be noted that the data source is the BindingSource rather than the DataTable. You may have to call WriteValue and then EndEdit perhaps.
Beast777
Oct 2nd, 2007, 07:03 AM
Crap, I have 2 bindingsources on this form and I typed the wrong one, no wonder no update. All is good now. Thanks for the reply JM.
youquijano
Sep 1st, 2008, 09:28 PM
I would have thought that that code would have pushed the new value to the data source before saving, but if it doesn't you can try calling the WriteValue method of the TextBox's Binding:this.textBox1.Bindings["Text"].WriteValue();That will force the value in the control to be written to the data source. It should be noted that the data source is the BindingSource rather than the DataTable. You may have to call WriteValue and then EndEdit perhaps.
hi, i have seen the WriteValue() method w/c says
Reads the current value from the control property and writes it to the data source.
i have controls in my forms which were binded on a datasource upon form load, when i try to change the value of my textbox in run time, the rowstate of the datasource does not change to added, do i need to trigger the WriteValue() method so that the datasource rowstate will change to added?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.