|
-
Oct 1st, 2007, 12:30 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Binding textbox to datagridview
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:
Code:
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?
-
Oct 1st, 2007, 06:19 PM
#2
Re: Binding textbox to datagridview
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:
Code:
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.
-
Oct 2nd, 2007, 07:03 AM
#3
Thread Starter
Fanatic Member
Re: Binding textbox to datagridview
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.
-
Sep 1st, 2008, 09:28 PM
#4
Lively Member
Re: Binding textbox to datagridview
 Originally Posted by jmcilhinney
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:
Code:
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|