Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Go bottom
Message
From
05/11/2007 15:48:26
 
 
To
05/11/2007 14:21:40
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Environment versions
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01266689
Message ID:
01266822
Views:
8
This message has been marked as the solution to the initial question of the thread.
Sergio,

Here's the issue:

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 (and, to be honest, I've found that the first method doesn't always seem to work correctly ... at least in the 1.1 Framework ... maybe it's better in the 2.0 Framework. I always use the second).

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")
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")
Now, you *were* consistent in your databindings, so that's fine. However, because you used the first syntax, then the syntax for the BindingContext has to correspond. So, it would be this instead:
this.BindingContext[this.grdPolicyChangesNotes.DataSource, "PolicyNotes"].Position = dsPolicyNotes.Tables["PolicyNotes"].Rows.Count - 1;
That should do the trick ... lemme know.

~~Bonnie






>Hello Bonnie, yes tried it but could not get it to work:
>My main form has a button that calls a child windows form. The child child window form does an insert into the dataset.
>
>See the button:
>
>
>private void btnNotes_Click(object sender, EventArgs e)
>  {
>     frmPolicyNotes frmNotes = new frmPolicyNotes(PolID);
>     frmNotes.Text = "Written Policy Notes";
>     frmNotes.ShowDialog();
>
>     // Get update dataset with inserted record
>     //Policy Notes
>     dsPolicyNotes = oPolicyNotesBiz.GetNotes(PolID);
>
>      grdPolicyChangesNotes.ReadOnly = true;
>      grdPolicyChangesNotes.DataSource = dsPolicyNotes;
>      grdPolicyChangesNotes.DataMember = "PolicyNotes";
>
>      //richtexbox just to display the notes ( field on my PolicyNotes table)
>       rtbPolicyChangesNotes.DataBindings.Clear();
>rtbPolicyChangesNotes.DataBindings.Add"Text",dsPolicyNotes, "PolicyNotes.Note");
>
>     // trying to implement bonnie suggestion
>     this.BindingContext[this.grdPolicyChangesNotes.DataSource].Position = dsPolicyNotes.Tables["PolicyNotes"].Rows.Count - 1;
>            count++;
>
>
>
>        }
>
>
>Sergio
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform