【问题标题】:C1FlexGrid get value from cell checkboxC1FlexGrid 从单元格复选框中获取值
【发布时间】:2018-05-28 20:46:38
【问题描述】:

我有一个 ComponentOne FlexGrid,其中填充了一个 DataTable。 每个 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

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

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

编辑:我刚刚在 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

【问题讨论】:

  • 你用的是什么版本?
  • .NET 2.0(是的,有点旧)和 ComponentOne C1FlexGrid 2.6.20101.545
  • C1FlexGrid 还是 C1FlexGridClassic?
  • 我认为是 C1FlexGrid
  • 这对我来说似乎是一个错误,我还不确定。明天我会回复你的。

标签: vb.net componentone c1flexgrid


【解决方案1】:

您应该像这样在未绑定的网格中设置选中的单元格值:

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

【讨论】:

  • 现在,当我首先使用SetCellCheck 设置它们时,我可以获得“未检查”值而不是一个空对象。但是,当我手动检查它们然后在循环内获取值时,值不会更新为“已检查”。
  • 首先,您是否将此列的数据类型设置为布尔值?
  • 当你访问gridDates.Item(I, columnwithCheck)时你得到了什么\不使用SetCellCheck?
  • gridDates.Item(I, columnwithCheck) 的情况下,我得到。当我不使用 SetCellCheck 并使用 getCellCheck 获取值时,一个“无”值,但是当我这样做时,我只是得到“未选中”(即使我检查了其中一些)。
  • 这不应该发生。顺便说一句,我不明白你为什么不在绑定模式下使用网格?如果绑定模式处于活动状态,您将不会看到这样的问题。您可以在 supportone.componentone.com 上报告事件吗?在这里用 Ticket ID ping 我。我可以在那里查看您的项目/示例。
【解决方案2】:

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

CheckBox.Checked = _checkResult

【讨论】:

    【解决方案3】:

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

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

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

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

    让我知道会发生什么。

    【讨论】:

    • 不,没用。我还将 columnwithCheck 更改为固定整数,但也没有用。
    • 你有明确的选项吗?如果没有,你能不能打开它,看看VS是否在代码的那个区域发现了可能的问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多