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

GridDataBoundGrid Cell BackColor Issues

Hello, I am trying to change the backcolor of the header row on my GridDataBoundGrid using the following code: Private Sub Header_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) If e.ColIndex > 1 And e.RowIndex = 0 Then e.Style.BackColor = System.Drawing.Color.AliceBlue grdResults.Refresh() End If End Sub Unfortunately, this method is not working for me. I know the code above is being executed because when I insert breakpoints at each line they''re hit during execution. Is there something that I am forgetting to do? I''m using Essential Suite 2.0.5.1 Thanks, Andrew

3 Replies

AD Administrator Syncfusion Team June 4, 2004 06:02 AM UTC

Two comments on your code. You do not want to do the grid.Refresh call from within PrepareViewStyleInfo. So, try removing it (I think this is what is causing things not to work, but am not 100% sure). The e.ColIndex > 1 will mean both the rowheader column and the first scrollable column will not be affected. Here is a little sample. Froum_prepareViewStyleInfo_7471.zip


AD Administrator Syncfusion Team June 5, 2004 11:05 AM UTC

I tried your example and it worked fine on my machine, which leaves me extremely confused. I removed the refresh call from my code and it still does not work. I also have the follwing code that affects the appearance of my grid: Private Sub GetColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) If Me.m_proportionalGridCell And e.Index = 4 Then If (CStr(Me.cboCustomerType.SelectedValue) = "R") Then Dim left As Integer = Me.grdResults.Model.ColWidths.GetTotal(2, 3) Dim right As Integer = Me.grdResults.Model.ColWidths.GetTotal(5, 7) e.Size = CInt((Me.grdResults.ClientRectangle.Width) - right - left) - 1 If (e.Size < 200) Then e.Size = 200 End If ElseIf (CStr(Me.cboCustomerType.SelectedValue) = "B") Then Dim left As Integer = Me.grdResults.Model.ColWidths.GetTotal(2, 3) Dim right As Integer = Me.grdResults.Model.ColWidths.GetTotal(5, 6) e.Size = CInt((Me.grdResults.ClientRectangle.Width) - right - left) - 1 If (e.Size < 200) Then e.Size = 200 End If End If e.Handled = True End If -------------------- AND ----------------------- Private Sub searchRetail() grdResults.DataSource = m_retail_search_results Dim gbc As New GridBoundColumn gbc.MappingName = "CustomerID" gbc.HeaderText = "Customer ID" grdResults.Model.Cols.Hidden(1) = True grdResults.GridBoundColumns.Add(gbc) gbc = New GridBoundColumn gbc.MappingName = "FirstName" gbc.HeaderText = "First Name" grdResults.GridBoundColumns.Add(gbc) . . . . gbc = New GridBoundColumn gbc.MappingName = "BusinessTelephone" gbc.HeaderText = "Business Telephone" grdResults.GridBoundColumns.Add(gbc) ''Initialize Columns grdResults.Binder.InitializeColumns() Could either of these code snippets be interferring with my function that changes the BackColor of the header row? Thanks, Andrew >Two comments on your code. > >You do not want to do the grid.Refresh call from within PrepareViewStyleInfo. So, try removing it (I think this is what is causing things not to work, but am not 100% sure). > >The e.ColIndex > 1 will mean both the rowheader column and the first scrollable column will not be affected. > >Here is a little sample. >Froum_prepareViewStyleInfo_7471.zip > >


AD Administrator Syncfusion Team June 5, 2004 11:19 AM UTC

You can just comment out your QueryColWidths handler to see if that is affecting your PrepareViewStyleInfo code. I suspect not, but don''t know for sure. Where/when is your searchRetail method being called. It is adding columns to the grid and also hiding a column. This may affect column numbering if you are checking for column numbers in PrepareViewStyleInfo, you should take into account these changes. If you can post a sample project showing the problem, maybe we can spot something here.

Loader.
Live Chat Icon For mobile
Up arrow icon