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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Row color change error

Thread ID:





19702 Oct 1,2004 10:19 AM UTC Feb 24,2005 09:20 AM UTC WinForms 8
Tags: GridControl
Asked On October 1, 2004 10:19 AM UTC

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

Administrator [Syncfusion]
Replied On 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
   End If
End Sub ''gridDataBoundGrid1_CurrentCellChanged

Replied On 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

Administrator [Syncfusion]
Replied On 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 WindowsApplication4_6250.zip

Replied On October 4, 2004 02:27 AM UTC

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

Frank Lin
Replied On 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.

Administrator [Syncfusion]
Replied On 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.

Frank Lin
Replied On 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.

Administrator [Syncfusion]
Replied On 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.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon