Home Forums WPF controls Xceed DataGrid for WPF Adorning Cells Based on Value Using C#

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

    Hi,

    I would like to adorn a cell based on the cell’s value. For example, I have an integer type column that is valid between 0 and 100. But, I would like to adorn cells in the column that have a value greater than 80. In the near future, the calculations will increase in complexity to be based on the values of multiple cells in a row (e.g. Column 1 cell is ‘Blue’ AND Column 2 cell is greater than 80).

    I am creating the grid structure (i.e. all columns are unbound) and populating it (using the .Items propery) at runtime in C#.

    Thanks for your help,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 3750 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Darrel,

    By “adorning cells” do you mean: “Changing the look of a Cell” or do your really mean “Placing something in an adorner layer of the cell” ?

    If the first option is the one you need, then be aware that you can place triggers in both the Style and/or the ControlTemplate of the Cell to achieve such a behavior

    You can refer to this quick example, which affects the background property of the Cell for the “Description” column whenever the “Read” property of the Data Item is “True”:

    <code>
    <Style.Triggers>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding=”{Binding RelativeSource={RelativeSource Self}, Path=FieldName}”
    Value=”Description”/>
    <Condition Binding=”{Binding Read}”
    Value=”True”/>
    </MultiDataTrigger.Conditions>
    <Setter Property=”Background”
    Value=”HotPink”/>
    </MultiDataTrigger>
    </Style.Triggers>
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 319 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    Thanks for the sample.

    Yes, I did mean that I would like to place something in the Adorner layer of the cell. But, I’m open to other solutions.

    I have a background thread that is reading the values of all controls (including rows/cells of the grid) and performing an assessment based on these values. It is then updaing the UI to reflect the results of the assessment. For the other non-grid controls (e.g. ComboBox), the control is adorned with an indicator to show the assessment result.

    My end goal is to give a visual indication to the user on/beside a cell based on the assessment of the background thread. The constraints are:
    1) Before the cell is in view, the indicator is known and could be placed (e.g. When the cell is in view, display a red exclamation mark beside the cell).
    2) While the cell is in view, the indicator currently applied to the cell could change (e.g. The background thread changes the red exclamation mark to a green check mark).

    Is the trigger based solution the best way to solve this problem? If yes, is there a way to tell the grid to recalculate the triggers (to solve the second constraint)?

    Thanks in advance,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 384 views)

    Xceed Support
    Member
    Post count: 5658

    I have some problems understanding the context you are explaining… :~

    Before going much further, is there a reason why you can’t use the same method as for non-grid control items (your ComboBox) for displaying the adorner?

    The first thing that comes to my mind, if you effectively can’t use the same strategy as for the other controls on the window/page, while preserving the largest possible customization factor is:

    – Derive from DataCell; in the derived class, you can add a function that would evaluate the status and update the adorner layer for the cell accordingly.
    – Derive from DataRow (override CreateCell() to use your custom DataCell type)
    – Derive from DataGridControl (override GetContainerForItemOverride() to use your custom DataRow type)

    Depending on the scalability you need for the evaluation of the status of the adorner, you could aslo:

    – Derive from Column, creating an event so you can add a handler that evaluate the status per column, and have the custom DataCell type use this event to retrieve the status for the adorner.

    Under any cases, I’d like to hear back from you, just to know if you have the tools you need, or to know how you decided to do it…

    Imported from legacy forums. Posted by Marcus [Xceed] (had 422 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    Thanks again. I’ll try to explain further.

    The reason I don’t think I can use the same strategy as for other controls is because I can only associate the adorner to the grid, not to a specific cell in the grid. For example, if I have a grid with 4 rows and 5 columns, an adorner associated to the grid control doesn’t visually show which of the 20 cells is a ‘problem cell’.

    I think the crux of my problem is that the cells/rows only exist when they are being displayed on the screen.

    I will look closer at using the inheritance based approach you describe and let you know what I figure out.

    Let me know if this post clears things up and you think of another solution.

    Thanks,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 4937 views)

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