我正在填充一个DataGridView
,如下面的代码所示。但是,虽然每个创建的行都与创建列的 parent 相关联,但DataGridView
我无法按列名引用行中的单元格。
有没有办法让我按列名引用?我宁愿避免使用基于整数的索引。
编辑:请注意,DataGridView 的列已使用 Visual Studio 设计器创建并正确命名。
Private Sub SetServiceOrders()
Dim Row As DataGridViewRow = Nothing
Dim RowValues As IServiceOrderDataGridViewRowValues = Nothing
Me.ServiceOrdersDataGridView.Rows.Clear()
If Not _ServiceOrders Is Nothing AndAlso _ServiceOrders.Count > 0 Then
For Each ServiceOrder As ServiceOrder In _ServiceOrders.Values
RowValues = ServiceOrder
Row = New DataGridViewRow()
Me.ServiceOrdersDataGridView.Rows.Add(Row)
With Row
'This Fails: "Specified argument was out of the range of valid values."
.Cells("StatusImageColumn").Value = My.Resources.BulletGreen24
.Cells("OrderDateColumn").Value = RowValues.Created
.Cells("CreatedByColumn").Value = RowValues.OwnerName
End With
Me.ServiceOrdersDataGridView.Rows.Add()
Next
End If
End Sub