Spread WPF Documentation
GrapeCity.Windows.SpreadSheet.Data Namespace / Cell Class / StyleName Property
Example


In This Topic
    StyleName Property (Cell)
    In This Topic
    Gets or sets the custom style for the cell.
    Syntax
    'Declaration
     
    <DefaultValueAttribute("")>
    Public Property StyleName As String
    'Usage
     
    Dim instance As Cell
    Dim value As String
     
    instance.StyleName = value
     
    value = instance.StyleName
    [DefaultValue("")]
    public string StyleName {get; set;}

    Property Value

    The custom style for the cell. The default value is an empty string, which means there is no custom style for the cell.
    Example
    This example creates a named style and adds it to the collection.
    gcSpreadSheet1.Sheets[0].NamedStyles.Add(new GrapeCity.Windows.SpreadSheet.Data.StyleInfo() { Background = new SolidColorBrush(Colors.Red), Name = "aaa", VerticalAlignment = GrapeCity.Windows.SpreadSheet.Data.CellVerticalAlignment.Center } );
    var style = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
    gcSpreadSheet1.Sheets[0].Cells[0, 0].StyleName = "aaa";
    gcSpreadSheet1.Sheets[0].Rows[7].StyleName = "aaa";
    style.Background = new SolidColorBrush(Colors.Blue);
    style.BorderLeft = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderTop = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderRight = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderBottom = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);    
    //Style applied to a rule
    var rule = GrapeCity.Windows.SpreadSheet.Data.AverageRule.Create(GrapeCity.Windows.SpreadSheet.Data.AverageConditionType.Above, style);
    rule.Ranges = new GrapeCity.Windows.SpreadSheet.Data.CellRange[] { new GrapeCity.Windows.SpreadSheet.Data.CellRange(1, 0, 5, 1) };
    gcSpreadSheet1.Sheets[0].ConditionalFormats.AddRule(rule);
    gcSpreadSheet1.Sheets[0].Cells[2, 0].Value = 25;
    gcSpreadSheet1.Sheets[0].Cells[1, 0].Value = 2;
    gcSpreadSheet1.Invalidate(); 
    
    private void button1_Click(object sender, RoutedEventArgs e)
            {
                gcSpreadSheet1.Sheets[0].Cells[0, 0].ResetStyleName();
                gcSpreadSheet1.Invalidate();
            }
    
    GcSpreadSheet1.Sheets(0).NamedStyles.Add(New GrapeCity.Windows.SpreadSheet.Data.StyleInfo() With {.Background = New SolidColorBrush(Colors.Red), .Name = "aaa", .VerticalAlignment = GrapeCity.Windows.SpreadSheet.Data.CellVerticalAlignment.Center})
    GcSpreadSheet1.Sheets(0).Cells(0, 0).StyleName = "aaa"
    GcSpreadSheet1.Sheets(0).Rows(7).StyleName = "aaa"
    Dim style As New GrapeCity.Windows.SpreadSheet.Data.StyleInfo()
    style.Background = New SolidColorBrush(Colors.Blue)
    style.BorderLeft = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderTop = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderRight = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderBottom = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    'Style applied to a rule
    Dim rule = GrapeCity.Windows.SpreadSheet.Data.AverageRule.Create(GrapeCity.Windows.SpreadSheet.Data.AverageConditionType.Above, Style)
    rule.Ranges = New GrapeCity.Windows.SpreadSheet.Data.CellRange() {New GrapeCity.Windows.SpreadSheet.Data.CellRange(1, 0, 5, 1)}
    GcSpreadSheet1.Sheets(0).ConditionalFormats.AddRule(rule)
    GcSpreadSheet1.Sheets(0).Cells(2, 0).Value = 25
    GcSpreadSheet1.Sheets(0).Cells(1, 0).Value = 2
    GcSpreadSheet1.Invalidate()
    
    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    GcSpreadSheet1.Sheets(0).Cells(0, 0).ResetStyleName()
    GcSpreadSheet1.Invalidate()
    End Sub
    See Also