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

Setting Border Color of a Column Header

Hi -
I need to draw a vertical line on the gridcontrol. I am using the left border of a column to do so using the following code:
this.Model.ColStyles[i].Borders.Left = new GridBorder(GridBorderStyle.Dashed, Color.Blue, GridBorderWeight.Thin);

However, the column header is not set. When i try and set it seperately using the following code, it is ignored (readonly?). this.Model[0, i].Borders.Left = ...

How can i change the color of the left border of a column header on demand?

Thanks,
Julie
Than


1 Reply

AD Administrator Syncfusion Team May 14, 2008 11:23 AM UTC

Hi Julie,

Thanks for the interest in Syncfusion Grid.

You can set the Border of the ColumnHeader by handling PrepareViewStyleInfo event. Please refer the following code snippet that shows how we can hanlde PrepareViewStyleInfo event to set the ColumnHeader of the Grid.


private void Form1_Load(object sender, System.EventArgs e)
{
for (int i = 1; i <= this.gridControl1.ColCount; i++)
this.gridControl1[0, i].CellValue = string.Format("{0}", Convert.ToChar(64 + i));
for (int i = 1; i <= this.gridControl1.ColCount; i++)
{
this.gridControl1.Model.ColStyles[i].Borders.Left = new GridBorder(GridBorderStyle.Solid, Color.Blue, GridBorderWeight.Thin);
}
for (int i = 1; i <= this.gridControl1.RowCount; i++)
this.gridControl1.Model.RowStyles[i].Borders.Top = new GridBorder(GridBorderStyle.Solid, Color.Red, GridBorderWeight.Thin);
this.gridControl1.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(gridControl1_PrepareViewStyleInfo);
}

private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if(e.RowIndex == 0 && e.ColIndex > 0)
{
e.Style.Borders.Left = new GridBorder(GridBorderStyle.Solid, Color.Blue, GridBorderWeight.Thin);
}
if (e.RowIndex > 0 && e.ColIndex == 0)
{
e.Style.Borders.Top = new GridBorder(GridBorderStyle.Solid, Color.Red, GridBorderWeight.Thin);
}
}


Please refer the following sample that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73642/main.htm

Regards,
Asem.



Loader.
Live Chat Icon For mobile
Up arrow icon