Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Adding Column Data To New DataGridView Row
 

Adding Column Data To New DataGridView Row

Now, I know how to create a new row in the DataGridView, but is there any way that I caninsert thecolumnvalues to this new row via some text boxes I have?

I'd like to be to specifically addto the column's in the new row from the column names.

GStachurski  Monday, February 04, 2008 7:30 PM

you can create a new row and cells, fill them and then add to your gridview

i believe that the columns have to be added in the designer to reference the name itself instead of the index

and keep in mind that the name of your column may not be the same as the header text

you can edit the columns in the designer to find the actual name in the properties

Dim d_row As DataGridViewRow = New DataGridViewRow

d_row.CreateCells(Me.DataGridView1)

d_row.Cells("your column name").Value = textbox1.text

Me.DataGridView1.Rows.Add(d_row)

or since you have a dataset which looks like it was created in the designer then you may need to add the new row to your datatable which is the actual datasource for your datagridview

Dim Bid_row As Data.DataRow = yourdataset.yourtable.NewRow

d_row("BidID") = textbox1.text

d_table.Rows.Add(d_row)

Jeff - www.SRSoft.us  Tuesday, February 05, 2008 7:29 PM

Nothing?

I can give a better example here.

If I have this code here...

Code Snippet

With Data2000DataSet.Data2000.Rows

.Add(txtTextBox1.Text, txtTextBox2.Text)

End With

Now, this will add the information that is within those text boxes into my DataGridView.

By this I mean that:

"txtTextBox1.Text" will be added under the 1st Column in the new row.

"txtTextBox2.Text" will be added under the 2nd Column in the new row.

This is due to the order that they are added... which is fine!

But I'm trying to specify which COLUMN that text is added to in the row, mainly by telling it the Column Name.

GStachurski  Tuesday, February 05, 2008 5:13 PM

you can create a new row and cells, fill them and then add to your gridview

i believe that the columns have to be added in the designer to reference the name itself instead of the index

and keep in mind that the name of your column may not be the same as the header text

you can edit the columns in the designer to find the actual name in the properties

Dim d_row As DataGridViewRow = New DataGridViewRow

d_row.CreateCells(Me.DataGridView1)

d_row.Cells("your column name").Value = textbox1.text

Me.DataGridView1.Rows.Add(d_row)

or since you have a dataset which looks like it was created in the designer then you may need to add the new row to your datatable which is the actual datasource for your datagridview

Dim Bid_row As Data.DataRow = yourdataset.yourtable.NewRow

d_row("BidID") = textbox1.text

d_table.Rows.Add(d_row)

Jeff - www.SRSoft.us  Tuesday, February 05, 2008 7:29 PM

Thanks for the information JS06.

the second part is EXACTLY what I was looking for.

Dim JS06 As TheFackingMan

GStachurski  Tuesday, February 05, 2008 8:08 PM

No problem,

I don't know what all you are doing with it but i have over 700 code samples on my website that may come in handy for you. I have several hundred that just deal with database (datatables, datagridviews, etc...)

Hope they help you

Jeff

I

I

I

I

\ /

Jeff - www.SRSoft.us  Tuesday, February 05, 2008 8:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview col headertext change
• Login failed for user ''(null)''. Reason: Not associated wi...
• Binding A comboBox
• Custom Object binding, how do i do this?
• No scroll bars in datagridview
• freezing datagrid for sometime while adding records.
• Unique constraint on multiple columns
• Simple Bound Controls not working on Master Detail relationship
• Datagridview SelectionChanged Event
• clear all values of databound components