We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Row color change error

Hi I have a checkbox cell in my Data grid. If the value is checked then that particular row’s color should change. I am using the databoundgrid’s PrepareViewStyleInfo event. I have written the following code in the event. If CType(e.Style.CellValue, String) = "Y" Then gridModel.RowStyles.Item(e.RowIndex).TextColor = Color.FromArgb(27, 89, 0) End If It gives an error “System.StackOverflowException” in the Syncfusion dll Please let me know how to change the row color runtime. Thanks, P.R.Anish

8 Replies

AD Administrator Syncfusion Team October 1, 2004 11:16 AM UTC

I think you will have to handle two events to get this to work. Use PrepareViewStyleInfo to set e.Style.BackColor by checking the value of the checkbox in the row, and then use CurrentCellChanged to tell the grid to repaint the row when the checkbox changes.
Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(sender As Object, e As GridPrepareViewStyleInfoEventArgs)
   If e.RowIndex > 0 And e.ColIndex > 0 Then
      ''Col1 is the name of teh checkbox column
      Dim checkBoxCol As Integer = Me.gridDataBoundGrid1.Binder.NameToColIndex("Col1")
      Dim o As Object = Me.gridDataBoundGrid1(e.RowIndex, checkBoxCol).CellValue
      Dim val As Boolean = o.ToString() = True.ToString()
      If val Then
         e.Style.BackColor = Color.LightGoldenrodYellow
      End If
   End If
End Sub ''gridDataBoundGrid1_PrepareViewStyleInfo


Private Sub gridDataBoundGrid1_CurrentCellChanged(sender As Object, e As EventArgs)
   Dim checkBoxCol As Integer = Me.gridDataBoundGrid1.Binder.NameToColIndex("Col1")
   If Me.gridDataBoundGrid1.CurrentCell.ColIndex = checkBoxCol Then
      Me.gridDataBoundGrid1.CurrentCell.ConfirmChanges()
      Me.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Row(Me.gridDataBoundGrid1.CurrentCell.RowIndex))
   End If
End Sub ''gridDataBoundGrid1_CurrentCellChanged


P. P.R.Anish October 3, 2004 08:25 AM UTC

Hi, The above code works fine for the cell, but I want the whole rows should change to different color. Anish


AD Administrator Syncfusion Team October 3, 2004 09:01 AM UTC

Did you try this code? It seems to color the whole row for me in this sample using 2.1.0.9. WindowsApplication4_6250.zip


P. P.R.Anish October 4, 2004 02:27 AM UTC

Hi, Thanks Clay, the example that you gave me helped a lot. Anish


FL Frank Lin February 23, 2005 08:41 AM UTC

Hi clay, I have a similar requirement as Anish. I wish to show some records according to column values in GDBG with highlighted backcolor when the form is opened. I know it''s a must to change the rows backcolor in PrepareViewStyleInfo event. Which event should be called to refresh the cell''s StyleInfo? Is it a must to loop all rows? thx a lot.


AD Administrator Syncfusion Team February 23, 2005 08:53 AM UTC

To force the whole grid to refresh, you can call grid.Refresh(); If you know what row you want to refresh, instead of refreshing the whole grid with grid.Refresh, you can call grid.RefreshRange passing it a GridRangeInfo object to specify the row.


FL Frank Lin February 24, 2005 05:05 AM UTC

I wish to highlight the row where "MstID" column equals 1. Here is what I input: Private Sub dgMaster_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles dgMaster.PrepareViewStyleInfo If e.RowIndex > 0 And e.ColIndex > 0 Then ''''Col is the name of the MstID column Dim Col As Integer = Me.dgMaster.Binder.NameToColIndex("MstID") If Me.dgMaster(e.RowIndex, Col).CellValue = 1 Then e.Style.BackColor = Color.LightGoldenrodYellow End If End If End Sub Where the form is opened, the GDBG would be blank. What''s happening? Thanks.


AD Administrator Syncfusion Team February 24, 2005 09:20 AM UTC

I do not know. As far as I can tell, that code should not cause the display to be empty. If you comment it out, does the problem go away? Do you see any exceptions listed in your output window? If so, the exceptions may be why the grid is empty. If you can provide a sample showing the problem, we can try to debug it here.

Loader.
Up arrow icon