values are not passing from datagridview into datarow

Posted by Oswaldlily under VB.NET on 4/1/2014 | Points: 10 | Views : 835 | Status : [Member] | Replies : 1
When I enter values row by row in datagrdivew,value should pass to datatable

Dim tb As New DataTable("GridTable")
tb.Columns.Add("Name", Type.[GetType]("System.String"))
tb.Columns.Add("Currency", Type.[GetType]("System.String"))
For Each d As DataGridViewRow In dg.Rows
Dim r As DataRow = tb.NewRow()
r("Name") = d.Cells(0).Value 'row1 cell 1
r("Currency") = d.Cells(1).Value 'row1 cell2
tb.Rows.Add(r)
Next

Here newly entering values are not passing from datagridview into datarow




Responses

Posted by: Allemahesh on: 4/1/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
I have checked you code and it is right.
I thing your foreach loop is not getting executing. I thing your DataGridViewRow is empty.
Just debug your code and check if your foreach is executing or not.

If every thing working, just try the below code:-

Dim tb As New DataTable("GridTable")
tb.Columns.Add("Name", Type.[GetType]("System.String"))
tb.Columns.Add("Currency", Type.[GetType]("System.String"))
For Each d As DataGridViewRow In dg.Rows
Dim r As DataRow = tb.NewRow()
r("Name") = d.Cells(0).Value
r("Currency") = d.Cells(1).Value
tb.Rows.Add(r)
tb.AcceptChanges()
Next


Happy Coding.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response