Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Reflect Changes In DataGridView
Message
From
23/05/2009 18:16:19
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01400525
Message ID:
01401670
Views:
36
>I have a DataGridView bound to a dataset. I also have a textbox bound to the same dataset. When the user make a change in the textbox, I want to reflect this change in the DataGridView.
>
>How do I make the change visible in the grid?


You shouldn't have to do anything, if you've databound them with the same syntax ... a common mistake that a lot of people make. Let me explain:

There are two ways (two different syntaxes) to specify databinding for any control and this results in two distinct binding objects. The problem is that you can't mix and match ... you have to stay consistent throughout the form. BTW, I prefer the second binding syntax.

So, in other words, if you bound your DataGrid with:
this.oGrid.DataSource = MyDataSet;
this.oGrid.DataMember = "MyTable";

//Then you have to use the following syntax with TextBoxes:
this.txtLastName.DataBindings.Add("Text", MyDataSet, "MyTable.LastName")

// And your CurrencyManager/BindingContext would be:
CurrencyManager cm = (CurrencyManager)this.BindingContext[MyDataSet, "MyTable"];
But if you bound your grid with:
this.oGrid.DataSource = MyDataSet.Tables["MyTable"];

//Then you use this syntax for TextBoxes:
this.txtLastName.DataBindings.Add("Text", MyDataSet.Tables["MyTable"], "LastName")

// And your CurrencyManager/BindingContext would be:
CurrencyManager cm = (CurrencyManager)this.BindingContext[MyDataSet.Tables["MyTable"]];
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform