1、关于DataGridView数据绑定是一件很简单的事情,只需要将其DataSource设置为你所需要的数据就行
2、如何遍历整个DataGridView,并且取出相应的数据进行操作
Dim drv As DataRowView
Dim x As Double
For i As Integer = 0 To DataGridViewName.Rows.Count - 1
drv = CType(DataGridViewName.Rows(i).DataBoundItem, DataRowView)
y = CType(drv("lat"), Double)
Next
3、如何对DataGridView选定的行进行操作
(1)、仅只对选中的那行进行操作
Dim drv As DataRowView
Dim x As Double
Dim y As Double
If (DataGridViewName.SelectedRows().Count > 0) Then
drv = CType(DataGridViewNameSelectedRows(0).DataBoundItem, DataRowView)
y = CType(drv("lat"), Double)
x = CType(drv("long"), Double)
End If
(2)、针对于选中的那一行,对其他的行进行操作
Dim drv As DataRowView
If (DataGridViewName.SelectedRows.Count > 0) Then
drv = CType(DataGridViewName.SelectedRows(0).DataBoundItem, DataRowView)
route_id = CType(drv("route_id"), Integer)
newsequence = CType(DataGridViewName.Rows(DataGridViewName.SelectedRows(0).Index + 1).Cells("col_sequence").Value, Integer)
'针对于选中的那一行,取其下一行的数据
End If