Programmatic Highlighting of Cells, Rows, Columns

5 posts, 1 answers
  1. Enal
    Enal avatar
    39 posts
    Member since:
    Oct 2011

    Posted 16 Jan 2012 Link to this post

    Hi - 

    I've been asked to provide an API to allow for programmatic highlighting on the grid (as opposed to selecting).
    For example on a 10x10 grid with blue cell backgrounds dynamically at runtime change Cell(3,4) to yellow background without anyone clicking, hovering or other direct user interactions. Basically an API along this line...

    void HighlightCell(int columnIndex, int rowIndex, Style highlightStyle);
    void HighlightRow(int rowIndex, Style highlightStyle);
    void HighlightColumn(int columnIndex, Style highlightStyle);

    Of course it would be nice to be able to easily reset it to defaults as well but yeah, we can just set them with the same API. Using row/column index or something else is not the issue.

    I've been fiddling with this for a while, with OnLoad events, StyleSelectors, ValueConverters etc, etc but nothing works cleanly.

    Do you have an example how to achieve this? Thanks!
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    Hi Enal,

    RadGridView is a virtualized control and all it visual elements are recycled and reused on scrolling. So, you need to keep that in mind when trying to set a property like background, foreground, etc. of its cells for example as it will be either lost or applied to another cell.
    My recommendation would be to keep the logic on a data level and work with CellStyleSelector for instance. You can expose a new property containing the information which style should be applied and update it on calling the methods you want.
    You can run through our online documentation and demos for a reference. 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Enal
    Enal avatar
    39 posts
    Member since:
    Oct 2011

    Posted 17 Jan 2012 Link to this post

    Hi Maya -

    Yes, that approach would be my preference as well. Unfortunately we are not using 'pure' objects with properties but each row is an ObservableCollection<object> which is the result of dynamically generated database queries with varying number of columns.

    I am sure we can find a way, but before going there - does the CellStyleSelector work dynamically? i.e. does it change Cell style based on property change without scrolling/moving the grid?

    Thanks!
  4. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    Hello Enal,

    SelectStyle method of StyleSelector will be invoked on changing the underlying property. You can test it on our demos as well - once you change value of UnitPrice property for an item that is greater than 30$, a different style will be applied. 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Enal
    Enal avatar
    39 posts
    Member since:
    Oct 2011

    Posted 17 Jan 2012 Link to this post

    Ok, perfect. Let's see what we can do with this. Thanks!
Back to Top