This is a migrated thread and some comments may be shown as answers.

Programmatic Highlighting of Cells, Rows, Columns

4 Answers 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Enal
Top achievements
Rank 1
Enal asked on 16 Jan 2012, 08:08 PM
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!

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Jan 2012, 07:51 AM
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 >>

0
Enal
Top achievements
Rank 1
answered on 17 Jan 2012, 02:14 PM
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!
0
Accepted
Maya
Telerik team
answered on 17 Jan 2012, 06:22 PM
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 >>

0
Enal
Top achievements
Rank 1
answered on 17 Jan 2012, 06:38 PM
Ok, perfect. Let's see what we can do with this. Thanks!
Tags
GridView
Asked by
Enal
Top achievements
Rank 1
Answers by
Maya
Telerik team
Enal
Top achievements
Rank 1
Share this question
or