Reputation: 253
Hi I am converting a old vb.net program to WPF and am having trouble. I imported some data to a datatable and dumped that into a datagrid. I now need to go row by row and extract the cell values and use them to update the appropriate database record.
This was working in my old program using:
For i = 0 To DataGridView1.Rows.Count - 1
cellvalue = Me.datagrid.Items(i).Cells(8).Value).ToString
(insert to database) etc
next
I been searching around and apparently its not as simple in WPF. But all the working examples i can find are all in C# which I am not that famillar with and cant seem to convert to work. So if someone can provide me some code (in vb) that would be much appreciated.
Upvotes: 1
Views: 6180
Reputation: 253
For Each item As DataRowView In datagrid.Items
cellvalue = item.Item("ColumnName")
(insert to database)
next
Upvotes: 0
Reputation: 16899
If you've already got a DataTable that contains your data, it is pretty easy to work with that:
Dim dt As New System.Data.DataTable
'...Load your data into DataTable
For Each rw As System.Data.DataRow In dt.Rows
cellValue = rw(8).ToString
'...insert to database
Next
Upvotes: 2