|
-
Jul 24th, 2008, 02:49 AM
#1
Thread Starter
Fanatic Member
[2008] DataGridView Binding to Table
Hi
I want to create a form in which the user will be able to Insert,Edit and Delete records from a database table also he will be able to Navigate the table (First,Previous,Next,Last) commands.
I am thinking of including a DataGridView and a number of textBoxes in my form so that the currently selected record from the datagridview will be displayed in the TextBoxes(each TextBox will be bound to a field of the table),also when the user navigate the GridView also the textboxes display the current row
My question is how can I do that?what component should I use for the navigation?how can I perform the databinding(textboxes)?How can I use ADO.NET in my form so for example when a user performs some changes to a record and doesn't press Save and then Navigate to the next row,if the RowState of the current row is Modified to display a warning telling the user whether he wants to save his changes or not
Any help
thanks
-
Jul 24th, 2008, 10:58 AM
#2
Re: [2008] DataGridView Binding to Table
Use a bindingsource. You assign the datatable to the bindingsource.DataSource, then assign the bindingsource to the DGV.DataSource property. Now for each of the textboxes, you add databindings to it using the same bindingsource as the datasource.
Something like this:
Code:
Me.BindingSource1.DataSource = myDataTable
Me.DataGridView1.DataSource = Me.BindingSource1
Me.TextBox1.DataBindings.Add("Text", Me.BindingSource1, "Some filed name here")
Me.TextBox2.DataBindings.Add("Text", Me.BindingSource1, "Some other filed name here")
' and so on....
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
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
|