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
close icon

Alternating colors in a GridListControl

How can you alternate the colors of the rows in with the GridListControl. With the .net controls there is a DrawItem property that allows you to write code to accomplish this task. Is there something similar in syncfusion. Thanks in advance. Bill

6 Replies

AD Administrator Syncfusion Team January 14, 2003 02:22 PM UTC

You can use the PrepareViewStyleInfo event of the embedded GridControl to handle this. //hook the event GridControl grid = gridListControl1.Grid; grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(grid_PrepareViewStyleInfo);
//the event handler
private void grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if( e.RowIndex > 0)
	{
		if(e.RowIndex % 2 == 1)
		{
			e.Style.BackColor = Color.Blue;
		}
		else
		{
			e.Style.BackColor = Color.AliceBlue;
		}
	}
}


BI Bill January 14, 2003 02:57 PM UTC

> You can use the PrepareViewStyleInfo event of the embedded GridControl to handle this. > > > //hook the event > GridControl grid = gridListControl1.Grid; > grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(grid_PrepareViewStyleInfo); > > > >
> //the event handler
> private void grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
> {
> 	if( e.RowIndex > 0)
> 	{
> 		if(e.RowIndex % 2 == 1)
> 		{
> 			e.Style.BackColor = Color.Blue;
> 		}
> 		else
> 		{
> 			e.Style.BackColor = Color.AliceBlue;
> 		}
> 	}
> }
> 
Clay do you have the code in VB.net? I am not familiar with C#. Thanks, Bill


AD Administrator Syncfusion Team January 14, 2003 10:12 PM UTC

Here it is. ' in form load 'hook the event Dim grid As GridControl = gridListControl1.Grid AddHandler grid.PrepareViewStyleInfo, AddressOf grid_PrepareViewStyleInfo
' the handler
'the event handler
Private Sub grid_PrepareViewStyleInfo(sender As Object, e As GridPrepareViewStyleInfoEventArgs)
    If e.RowIndex > 0 Then
        If e.RowIndex Mod 2 = 1 Then
            e.Style.BackColor = Color.Blue
        Else
            e.Style.BackColor = Color.AliceBlue
        End If
    End If
End Sub 'grid_PrepareViewStyleInfo    


BI Bill January 15, 2003 12:27 PM UTC

Clay, I get an bad Name error when I Dim grid As GridControl = gridListControl1.Grid. It does not like the GridControl namespace. Any suggestions. I am new to VB.Net so any info would be helpful. Bill


AD Administrator Syncfusion Team January 15, 2003 04:10 PM UTC

Try adding Imports Syncfusion.Windows.Forms.Grid as the first line in your file (outside the class definition).


BI Bill January 16, 2003 10:26 AM UTC

Clay, Thanks a lot. Bill

Loader.
Live Chat Icon For mobile
Up arrow icon