Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

DataGrid and TextBoxes bound to DataView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shehab Kamal - 24 Jun 2007 15:30 GMT
Hi all,
A .Net 1.1 question
I have a DataGrid bound to a DataView and 2 TextBoxes bound to 2 columns in
the same DataView.
When I change the selected row in the DataGrid the text in the TextBoxes
change (The currency manager fires the PositionChanged event and the
TextBoxes adjust their data consequently)
The problem is when I change the text in one of the TextBoxes the DataGrid
is not synchronized with what is dispalyed in the TextBoxes.

To solve this problem I had to call EndEdit() on the DataRowView being
edited on Leave and Enter events of all controls? (If I just call EndEdit()
in the Leave event it requires to leave the first TextBox then leave the
second to see the data changed)

Is this the correct solution? Am I missing something? Are there any better
solutions?
I really appreciate if you provide me with a decent solution and an
explanation of what really happens?
Manish Bafna - 25 Jun 2007 10:52 GMT
Hi,
Below link provides solution to your query
http://windowsclient.net/samples//Go%20To%20Market/Data%20Binding/DataBinding%20
FAQ.doc

Search for "stay in sync" in above link
Signature

Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> Hi all,
> A .Net 1.1 question
[quoted text clipped - 15 lines]
> I really appreciate if you provide me with a decent solution and an
> explanation of what really happens?
Shehab Kamal - 25 Jun 2007 14:35 GMT
Thank you for your reply. But this is not hte case
I am sure that the BindingManagerBase is the same for the Grid and the TextBox
I executed this code
if
(this.BindingContext[grdInformation.DataSource].Equals(txtName.DataBindings["Text"].BindingManagerBase))
{
 MessageBox.Show("equal");
}
and I always see the MessageBox.

The point is, the view is in sync (when I clcik a row in the DataGrid I see
the correct data in the TextBox) but when I edit the name in the TextBox and
leave the TextBox the data is not reflected in the DataGrid. I have to call
EndEdit() on the current DataRowView. Any suggestions
Manish Bafna - 25 Jun 2007 14:52 GMT
Hi,
I would suggest to give it a try.In msdn website also they have suggested
this only.Write your code in following format:

this.dataGridView1.DataSource = dataSet;
this.dataGridView1.DataMember = "Numbers";
this.textBox1.DataBindings.Add("Text", dataSet, "Numbers.Name", true);

instead of in this format:

this.dataGridView2.DataSource = dataTable;
this.textBox2.DataBindings.Add("Text", dataTable, "Name", true);
Signature

Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> Thank you for your reply. But this is not hte case
> I am sure that the BindingManagerBase is the same for the Grid and the TextBox
[quoted text clipped - 10 lines]
> leave the TextBox the data is not reflected in the DataGrid. I have to call
> EndEdit() on the current DataRowView. Any suggestions
Shehab Kamal - 26 Jun 2007 07:38 GMT
It is a matter of refresh!
I have the following

dataView1.Table = dataTable1; // A DataTable that has 2 column "ID", "Name"
dataGrid1.DataSource = dataView1;
txtID.DataBindings.Add(new Binding("Text", dataView1, "ID"));
txtName.DataBindings.Add(new Binding("Text", dataView1, "Name"));

The TextBoxes and the DataGrid are in sync because they share the same
CurrencyManager. However when I change a value in the TextBox it is not
reflected in the DataGrid unless I choose another row.
To solve it I have added the following code the Leave and Enter events of
the TextBoxes
// 1) Change the Posintion of the CurrencyManager
this.BindingContext[dataGrid1.DataSource].Position++;
// OR 2) Invoke EndEdit
dataView1[this.BindingContext[dataGrid1.DataSource].Position].EndEdit();
// OR 3) Refresh the DataGrid
dataGrid1.Refresh();

I suggets the second method.
Thank you for your help and the great document.
Shehab Kamal - 26 Jun 2007 12:21 GMT
http://windowsclient.net/samples//Go%20To%20Market/Data%20Binding/DataBinding%20
FAQ.doc

> Search for "stay in sync" in above link

We were looking in the wrong direction, we should search for
"Q. Why doesn’t DataSourceUpdateMode.OnPropertyChanged work for ADO.NET data
sources?"
Agian a very great document.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.