DataGrid and TextBoxes bound to DataView

G

Guest

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?
 
G

Guest

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
 
G

Guest

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);
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top