hi,i have a three columns in empty datagridview to get a input from user.i had a doubt to create a new row after entering the values in those previous cells

Recommended Answers

Dim dt as new datatable
' Code to add columns to table
        dt.Columns.Add("A", Type.GetType("System.String"))
        dt.Columns.Add("B", Type.GetType("System.String"))
        dt.Columns.Add("C", Type.GetType("System.String"))
'Binding the rows to gridview
        DataGridView1.DataSource = dt
' Code to add new row
        Dim dr As DataRow
        dr = dt.NewRow
        dt.Rows.Add(dr)
Jump to Post

All 4 Replies

Dim dt as new datatable
' Code to add columns to table
        dt.Columns.Add("A", Type.GetType("System.String"))
        dt.Columns.Add("B", Type.GetType("System.String"))
        dt.Columns.Add("C", Type.GetType("System.String"))
'Binding the rows to gridview
        DataGridView1.DataSource = dt
' Code to add new row
        Dim dr As DataRow
        dr = dt.NewRow
        dt.Rows.Add(dr)

Shorten it down like this:

dim dr As New DataRow("Your row's name")
dt.Rows.Add(dr)

Hi Eternal Newbie,
Are you sure we can Declare and assign datarow like what you shown above?

I'm replacing the part to create a new row. Well, it's working if he's already had a table in his project.

Be a part of the DaniWeb community

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