FlexGrid for WinForms
Style Property (OwnerDrawCellEventArgs)
Example 



Sets or sets the CellStyle object used to paint the cell.
Syntax
'Declaration
 
Public Property Style As CellStyle
'Usage
 
Dim instance As OwnerDrawCellEventArgs
Dim value As CellStyle
 
instance.Style = value
 
value = instance.Style
public CellStyle Style {get; set;}
public:
property CellStyle^ Style {
   CellStyle^ get();
   void set (    CellStyle^ value);
}
Remarks

This parameter is often used to provide dynamic formatting based on cell contents. For example, if the cell contains a value outside a given range, the event handler may assign a new style to this parameter.

Although it is legal to modify the members of the CellStyle parameter in this event, this is not recommended, since the change will affect other cells that may be using this style.

Example
The code below uses the OwnerDrawCell event to highlight cells that indicate low stock levels.
// create style used to display low-stock items
CellStyle cs = _flex.Styles.Add("Critical");
cs.BackColor = Color.Red;
            
private void _flex_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{
    // ignore fixed cells
    if (e.Row < _flex.Rows.Fixed || e.Col < _flex.Cols.Fixed)
        return;
        
    // apply custom style if reorder level is critical
    if (_flex.Cols[e.Col].Name == "UnitsInStock")
    {
        // change the style by applying the "Critical" style to the Style parameter
        // (do not change the e.Style.BackColor property directly since that would
        // affect other cells that use this style)
        if ((short)_flex[e.Row, "UnitsInStock"] < (short)_flex[e.Row, "ReorderLevel"])
            e.Style = _flex.Styles["Critical"];
    }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

OwnerDrawCellEventArgs Class
OwnerDrawCellEventArgs Members

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Send Feedback