4

我有一个用 DataTable 填充的 ComponentOne FlexGrid。每个 DataTable 列都在此网格中分配了自己的列,但还有一个附加列(在设计器中声明)配置为带有复选框(布尔类型)的单元格,用户将在之后选择值。

我用 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

我设置了一个断点,发现我得到一个空对象,它没有得到任何复选框的当前值。

如何以正确的方式检索该值?

编辑:我刚刚在设计器中添加了与网格相关的代码:

    '
    '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
4

3 回答 3

3

您应该在未绑定的网格中设置选中的单元格值,如下所示:

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
于 2018-06-11T09:34:15.693 回答
0

尝试消除 With/End With,将您的网格名称添加到以 .something 开头的所有区域。这意味着有问题的行将结束为:

Dim value As C1.Win.C1FlexGrid.CheckEnum = gridDates.GetCellCheck(I, columnwithCheck)

确保上面一行中的 gridDates 是您向用户显示的实际实例。

还要确保 columnwithCheck 是一个整数并且它是正确的列。

让我知道发生什么事。

于 2018-06-07T17:15:02.780 回答
0

为每个运行它,或者最好循环运行,然后将结果分配给您需要的任何格式。

CheckBox.Checked = _checkResult

于 2018-06-06T16:19:32.310 回答