我有一个填充了DataTable的ComponentOne FlexGrid。 每个DataTable列都在此网格中分配了自己的列,但是有一个额外的列(在Designer中声明)配置为带有复选框的单元格(类型为boolean),用户将在之后选择值。
我用for循环填充网格:
With My_StoreProcedure()
For I As Integer = 1 To .Rows.Count()
gridDates.Item(I, cPatron)= .Rows(I - 1).Item("patron")
gridDates.Item(I, cColumn2)= .Rows(I - 1).Item("anothercolum2")
gridDates.Item(I, cColumn3)= .Rows(I - 1).Item("anothercolum3")
[..other 3 columns more...]
Next I
然后用户从网格结果中选中复选框,点击“获取”按钮调用包含另一个循环的方法,我有这个内部循环来获取值:
With gridDates
For I As Integer = 1 To .Rows.Count() - 1
'Dim celda As Object = gridDates.Item(I, 8)
'Here it is where it doesn't work:
Dim value As C1.Win.C1FlexGrid.CheckEnum = .GetCellCheck(I, columnwithCheck)
If value = C1.Win.C1FlexGrid.CheckEnum.TSChecked Then
Dim patron As String = gridDates.Item(I, 1).ToString
Dim value2 As String = gridDates.Item(I, 2).ToString
Dim value3 As Char = CChar(gridDates.Item(I, 3))
[some other values...]
StoreSave(patron, value2, value3, ...)
End If
Next I
End With
我设置了一个断点,发现我得到一个空对象,它没有得到任何复选框的当前值。
如何以正确的方式检索该值?
编辑:我刚刚在Designer中添加了与网格相关的代码:
'
'gridDates
'
Me.gridDates.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
Me.gridDates.AllowFreezing = C1.Win.C1FlexGrid.AllowFreezingEnum.Both
Me.gridDates.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
Me.gridDates.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
Me.gridDates.ColumnInfo = resources.GetString("gridDates.ColumnInfo")
Me.gridDates.ExtendLastCol = True
Me.gridDates.KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.MoveAcross
Me.gridDates.Location = New System.Drawing.Point(12, 104)
Me.gridDates.Name = "gridDates"
Me.gridDates.Rows.Count = 500
Me.gridDates.Rows.DefaultSize = 19
Me.gridDates.SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Row
Me.gridDates.Size = New System.Drawing.Size(742, 261)
Me.gridDates.StyleInfo = resources.GetString("gridDates.StyleInfo")
Me.gridDates.TabIndex = 1
答案 0 :(得分:2)
您应该在未绑定的网格中设置选中的单元格值,如下所示:
gridDates.SetCellCheck(rowIndex, columnIndex, checkEnum)
然后,您可以稍后使用GetCellCheck
访问这些值。在这种情况下使用此代码:
If gridDates.GetCellCheck(I, columnwithCheck) = C1.Win.C1FlexGrid.CheckEnum.TSChecked Or gridDates.GetCellCheck(I, columnwithCheck) = C1.Win.C1FlexGrid.CheckEnum.Checked Then
' When Checked
ElseIf gridDates.GetCellCheck(I, columnwithCheck) = C1.Win.C1FlexGrid.CheckEnum.TSUnchecked Or gridDates.GetCellCheck(I, columnwithCheck) = C1.Win.C1FlexGrid.CheckEnum.Unchecked Then
' When Unchecked
Else
' Other state
End If
但是,在您的情况下,您已为单元格设置了布尔值。在这种情况下,您应该检索单元格的值并使用布尔值
有条件地检查If gridDates.Item(I, columnwithCheck) = True Then
' When Checked
ElseIf gridDates(I, columnwithCheck) = False Then
' When Unchecked
Else
' This won't be reachable
End If
答案 1 :(得分:0)
为每个运行此操作,或者更优选地循环执行此操作,然后将结果分配给您需要的任何格式。
CheckBox.Checked = _checkResult
答案 2 :(得分:0)
尝试消除With / End With,将您的网格名称添加到所有区域.something。这意味着有问题的行将以:
结束Dim value As C1.Win.C1FlexGrid.CheckEnum = gridDates.GetCellCheck(I, columnwithCheck)
确保上面一行中的gridDates是您向用户显示的实际实例。
还要确保columnwithCheck是一个整数,并且它是正确的列。
让我知道会发生什么。