I want a row to add data grid view that is linked to dataset and datatable.
Aftet that I want to that new row in the first cell i want to put a new value (data)

myConn.Open()
        myCommand1.CommandText = "select * from groups"
        myCommand1.Connection = myConn
        myAdapter1.SelectCommand = myCommand1
          MyBuilder1 = New MySql.Data.MySqlClient.MySqlCommandBuilder(myAdapter9)
        myAdapter1.Fill(MyDataset1, "groups")
        MyDataTable1 = MyDataset1.Tables("groups")
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.DataSource = MyDataTable
        myConn.Close()

Recommended Answers

All 4 Replies

I want a row to add data grid view that is linked to dataset and datatable.
Aftet that I want to that new row in the first cell i want to put a new value (data)

myConn.Open()
        myCommand1.CommandText = "select * from groups"
        myCommand1.Connection = myConn
        myAdapter1.SelectCommand = myCommand1
          MyBuilder1 = New MySql.Data.MySqlClient.MySqlCommandBuilder(myAdapter9)
        myAdapter1.Fill(MyDataset1, "groups")
        MyDataTable1 = MyDataset1.Tables("groups")
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.DataSource = MyDataTable
        myConn.Close()

You have to add a new DataRow to your datatable and assign a value to the first item of that datarow , the datagridview , being bound to your datatable will show the newly added row automatically

Dim row As DataRow = MyDataset1.Tables("groups").NewRow
dim v As Integer=10 ' Value
row.Item(0)=v
MyDataset1.Tables("groups").Rows.InsertAt(row, 0) ' Adds row at position 0

Thanks this was the solutions where I looking for!

There remains a small problem:


After I use filter (see code) , i want to add new ROW (with your code)

The new ROW is not displayed in datagridview1 but well added to dataset
I get no error message

Private Sub Filter1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Filter1.TextChanged
        'Filter group
        Dim keywords As String = filter1.Text
        MyDataset1.Tables("groups").DefaultView.RowFilter = "group Like '*" & keywords & "*'"
       
    End Sub

How can I fix this so I do see the new added ROW in the datagridview1 after a filter command?

solved, simply remove filter!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.