Home Products Downloads Purchase Support Forum About Blog

How to customize cell styles in VIBlend DataGridView for WinForms

by viblend 27. July 2010 04:17

Each cell within the VIBlend WinForms DataGridView control can have its own style. A cell style can modify properties like text format, background color, foreground color, border color, and font. In most cases multiple cells will share particular style characteristics. To customize a cell style, start by creating a new instance of the GridCellStyle class.

GridCellStyle cellStyle = new GridCellStyle();

The next step is to set the appropriate values for each Style propoperty:

FillStyle cellFillStyle = new FillStyleGradientEx(Color.Aqua, Color.Aqua, Color.Aqua, Color.Aqua,
90, 0.7f, 0.7f);

cellStyle.TextColor = Color.Black;
cellStyle.TextColorSelected = Color.Black;
cellStyle.Font = this.Font;
cellStyle.FillStyle = cellFillStyle;
cellStyle.FillStyleSelected = cellFillStyle;
cellStyle.BorderColorSelected = Color.Transparent;
cellStyle.BorderColor = Color.Transparent;

 Finally, apply the style to one or more grid cells:

HierarchyItem rowItem = this.Grid1.RowsHierarchy.Items[1];
HierarchyItem colItem = this.Grid1.ColumnsHierarchy.Items[1];
this.Grid1.CellsArea.SetCellDrawStyle(rowItem, colItem, cellStyle); 

You can also apply a cell style to all grid cells in any row:

          HierarchyItem rowItem = this.Grid1.RowsHierarchy.Items[1];

rowItem.CellsStyle = cellStyle;

Similarily, you can apply a cell style to all grid cells in any column:
HierarchyItem colItem = this.Grid1.ColumnsHierarchy.Items[1];
colItem.CellsStyle = cellStyle;
Comments are closed

About the author

Some text that describes me

Tag cloud

Recent comments

Comment RSS
Copyright © 2011 VIBlend  
Terms of Use | Privacy Policy
WinForms Controls Purchase Online About Us
DataGrid Navigation Pane Technical Support Blog
ScrollBar TreeView
ListBox ProgressBar Downloads Register
ComboBox Buttons
TabControl Editors Documentation Client Login

VIBlend Blog is powered by BlogEngine.NET