Home Forums WPF controls Xceed DataGrid for WPF change CELL COLOR in Datagrid

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26754 |

    Hi,
    How to change the color of a cell(Like ERROR Display) in datagrid ?
    I’m using xceed datagrid 2.0.

    Please give me a solution ASAP

    Imported from legacy forums. Posted by Anand (had 4140 views)

    Xceed Support
    Member
    Post count: 5658

    You can create an implicit style that targets DataCell and that sets the cells’ Background property. If you want to use different colors depending on content, you can use DataTriggers.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 438 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,
    If suppose i have 10 headers(columns) and 100 rows.
    I’m just binding my collection(Ex. List<string[ ]> ) with ItemsSource property.
    Then If i want to change the background color of some of cells(that i know in binding time only) How to change the cell background. Please give me a example.

    Imported from legacy forums. Posted by Anand (had 795 views)

    Xceed Support
    Member
    Post count: 5658

    As previously stated, you can use a style that has datatriggers. Here is a quick example extracted from the documentation that demonstrates how to set the background of rows using a style and DataTriggers.

    <code>
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Orders}”/>
    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <Style.Triggers>
    <DataTrigger Binding=”{Binding Path=[EmployeeID]}” Value=”1″>
    <Setter Property=”Background” Value=”Pink”/>
    </DataTrigger>
    <DataTrigger Binding=”{Binding Path=[EmployeeID]}” Value=”3″>
    <Setter Property=”Background” Value=”Blue”/>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </Grid.Resources>
    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}”/>
    </Grid>
    </code>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 3612 views)

    User (Old forums)
    Member
    Post count: 23064

     

     Hi

    Is it Possible to make  Value like value(Employee ID) greater than 100  color is Pink and If value(EmployeeID) less than 50 color is Blue.?

    One more doubt. Is it possible to define all the above example in C#?

    One more requirement. Is it possible to define the above  first 50 Rows having some condition and remaining 50 rows  having some conditions ?

     

     

    Imported from legacy forums. Posted by Anand (had 1406 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,
    Please can anybody tell me the above requirement is possible or not ?

    Imported from legacy forums. Posted by Anand (had 696 views)

    Xceed Support
    Member
    Post count: 5658

    You can create a custom DataTemplateSelector and set it to the CellContentTemplateSelector property of the column (or columns) whose cell color you want to change.

    The CustomViews sample application demonstrates how to create a DataTemplateSelector.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 431 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok Thanks. I’ll try it and catch u back

    Imported from legacy forums. Posted by Anand (had 1968 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.