Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Data Manipulation in DataGridView
 

Data Manipulation in DataGridView

Hi !

At run time , I added new datarows and a column in datagridview. If I update the changes i have made in database, only rows getting updatted but the column is not updatting. The code I have written is as follows,

Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown

Dim strColName As String
Dim row1 As System.Data.DataRow
Dim row2 As System.Data.DataRow
Dim column As New System.Data.DataColumn

If (e.KeyCode = Keys.Enter) Then

row1 = s1Table.NewRow
row2 = s2Table.NewRow
s1Table.Rows.Add(row1)
s2Table.Rows.Add(row2)

End If

If (e.KeyCode = Keys.ControlKey) Then

strColName = DataGridView1.CurrentRow.Cells(2).Value
s2Table.Columns.Add(column)
column.ColumnName = strColName
MsgBox("Column Added")

End If

End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Dim command_builder As OleDbCommandBuilder

command_builder = New OleDbCommandBuilder(objDataAdapter)
command_builder = New OleDbCommandBuilder(objDataAdapter1)

objDataAdapter.Update(s1Table)
objDataAdapter1.Update(s2Table)

End Sub

StephenRaj  Thursday, June 21, 2007 12:10 PM

try add

DataGridView1.AutoGenerateColumns = true;

before loading your datatable.

hrubesh  Thursday, June 21, 2007 5:08 PM

try add

DataGridView1.AutoGenerateColumns = true;

before loading your datatable.

hrubesh  Thursday, June 21, 2007 5:08 PM

You can use google to search for other answers

Custom Search

More Threads

• Project Publish Error
• DataGridView (VB.net) problems, nonvisible rows are still visible or the DataGridView is empty despite having a DataSource
• bind DataGridView to 2 dimension array
• Inherited a DataGridView in a form,how to make it editable in designer?
• DataGridViewComboBoxColumn
• DataGridView STILL adds two new rows on 'escape'
• NumeriUpDown Databinding New value does not update or persist
• Reposition to specific record using Bound controls on Windows form
• Turning off DataGridView tooltip when over error icon
• DataGridView Problems