4

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
Mr_LinDowsMac
  • 2,644
  • 9
  • 56
  • 75
  • What version are you using? – Nilay Vishwakarma Jun 04 '18 at 16:48
  • .NET 2.0 (yes, a bit old) and ComponentOne C1FlexGrid 2.6.20101.545 – Mr_LinDowsMac Jun 04 '18 at 22:01
  • C1FlexGrid or C1FlexGridClassic? – Nilay Vishwakarma Jun 05 '18 at 05:03
  • I think is C1FlexGrid – Mr_LinDowsMac Jun 05 '18 at 14:20
  • This looks like a bug to me, I am not sure yet. I will get back to you tomorrow. – Nilay Vishwakarma Jun 07 '18 at 13:26
  • Is the grid bound to data source from designer? What exactly is gridDates? What are you doing in: `gridDates.Item(I, cPatron)= .Rows(I - 1).Item("patron")` Also why column names? Ideally you should bind the datasource with grid and then fill the unbound columns later. Should I assume 'patron' , 'othercolumn1,2'... are unbound columns – Nilay Vishwakarma Jun 08 '18 at 11:48
  • There is no datasource bound from designer. gridDates is just an instance of C1Flexgrid, and is filled with a DataTable with `.Rows(I - 1).Item("patron") `. "patron" or "anothercolumn1" are column names of the DataTable returned in My_StoreProcedure(). Only column with checkbox is not being filled with the DataTable. – Mr_LinDowsMac Jun 08 '18 at 15:24
  • I see, then all of your column's were created in designer right? Can you add the code regarding FlexGrid in design mode? Do you have any isolated project? I have 2.6.20101.545 build but I cannot reproduce this. Any help reproducing this would be appreciated ;) – Nilay Vishwakarma Jun 08 '18 at 16:53
  • Also, how are you setting the value in `columnwithCheck` column – Nilay Vishwakarma Jun 08 '18 at 17:01
  • @NilayVishwakarma Updated question including Designer generated code. About value in columnwithCheck, I tried both with a constant or replacing it directly with an integer (ensuring is the right column). – Mr_LinDowsMac Jun 09 '18 at 14:15
  • A quick question, can you post the content of `gridDates.ColumnInfo` – Nilay Vishwakarma Jun 11 '18 at 06:46

3 Answers3

3

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
Nilay Vishwakarma
  • 3,105
  • 1
  • 27
  • 48
  • Now I'm able to get "Unchecked" values instead an empty object when I set them first with `SetCellCheck`. However, values doesn't get updated to "Checked" when I manually check them and then get values inside the loop. – Mr_LinDowsMac Jun 11 '18 at 17:16
  • For one, have you set datatype to boolean for this column? – Nilay Vishwakarma Jun 11 '18 at 19:24
  • What do you get when you access, `gridDates.Item(I, columnwithCheck)` when using\not using SetCellCheck? – Nilay Vishwakarma Jun 11 '18 at 19:25
  • In the case of `gridDates.Item(I, columnwithCheck)` I get . When I don't use SetCellCheck and I use getCellCheck to get value, a "None" value, but when I do, I just get "Unchecked" (even If I checked some of them). – Mr_LinDowsMac Jun 12 '18 at 21:21
  • That should not happen. BTW, I don't understand why don't you use grid in bound mode? With bound mode active you wouldn't have seen such an issue. Can you report an incident on supportone.componentone.com? Ping me with the Ticket ID here. I can look into your project/sample there. – Nilay Vishwakarma Jun 13 '18 at 06:06
  • I didn't want to use `gridDates.DataSource = myDatable` because I don't want all fields from that DataTable displayed. But apparently is the only way that the checkbox works. – Mr_LinDowsMac Jun 13 '18 at 16:21
  • You can always toggle the visible property of column. `flex.Cols("myColName").Visible = False` – Nilay Vishwakarma Jun 15 '18 at 08:42
0

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

CheckBox.Checked = _checkResult

0

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.

Nandostyle
  • 344
  • 2
  • 12