C1FlexGrid get value from cell checkbox

3.2k Views Asked by At

I have a ComponentOne FlexGrid that is filled with a DataTable. Every DataTable column has its own column assigned in this grid, but there is an additional column (declared in the Designer) configured like cells with checkboxes (type boolean) and the user will select values after.

I fill the grid with a for loop:

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

Then user select checkboxes from the grid result obtained hit a 'Get' button which calls a method that contains another loop, I have this inside loop to get the value:

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

I set a breakpoint and found that I get an empty object, it doesn't get the current value of any checkbox.

How can I retrieve that value in a proper way?

Edit: I just added code generated related to the grid in 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
3

There are 3 best solutions below

0
On

Run this for each, or more preferably loop through, then assign the results to whatever format you need.

CheckBox.Checked = _checkResult

2
On

Try eliminating With/End With, add your grid name to all areas starting .something. This mean that the problematic line will end as:

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

Make sure gridDates in the line above is the actual instance you are displaying to the user.

Also make sure columnwithCheck is an integer and that it is the right column.

Let me know what happens.

7
On

You should set checked cell value in an unbound grid like this:

gridDates.SetCellCheck(rowIndex, columnIndex, checkEnum)

Then only, you can access the values later with GetCellCheck. Use this code in that case:

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

However, in your case, you have set the boolean value for cell. In this case you should retrieve the value of cell and check conditionally with boolean

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