How to show "undefined" value without affecting performance in data grid/tree?

1 Answer 69 Views
GridView TreeView
Bob
Top achievements
Rank 1
Bob asked on 05 Dec 2023, 03:53 PM

I just started WPF trial. I need help though. I am going to have large grids (10Ks rows x 100 columns) with frequent update of certain cells (100s upd/sec).

I am not sure I can use your virtual grid - need more time to understand what are the drawbacks.

So I use RadGridView (see below - this is not final version - just a first try - what I quickly read in your article on making grid more performant).

Columns are made in C# and bound to dictionaries using string key like: `Binding("f[NAME].Value")` where `Value` is of type object (this is best I can do - dont ask - a requirement i cannot circumvent)

Now, what is my question here - when I load grid with data initially - most of the values in cells arent available yet. I am asked to display something to highlight that state. Also sometime some rows might get unavailable in the middle of use. But bottom line - these "unavailable" cues are going to live may be 0.5% of the grid life-time..

I dont want to write cell templates that will lengthen the visual tree and  make grid slow for something that i need for very short period of time.. 

Is there a way to optimise it?

One theory - add something to the visual tree in the beginning and then take it away.. (like walking visual tree manually and inserting a semi-transparent red border or something like that? or changing template of rows, that have became available, into lightweight ones). Concern here - binding might get broken after manipulation with visual tree..

Or I can set all the values to a string like "N/A". However concern here is that what happens with the columns types in this case? Wont this screw the grid ability to sort/filter - because columns will pick up initial "string" type and later, when I change it to real data, (can be date/number/etc) - they break down completely.

Can I set columns type explicitely after N/A disappeared (however not clear - N/A might stay in some rows longer than in others and few could be N/A for lot longer)...

Any trick you can recommend?

NOTE: the same question applies on tree view (even more so)

 

<telerik:RadGridView x:Name="dg" ItemsSource="{Binding data}" ValidatesOnDataErrors="InEditMode" IsPropertyChangedAggregationEnabled="False" GroupRenderMode="Flat" ShowGroupPanel="False"AutoGenerateColumns="False"CanUserFreezeColumns="False"RowIndicatorVisibility="Collapsed"CanUserResizeColumns="False">

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 08 Dec 2023, 02:05 PM

Hello Bob,

There are different strategies that you can utilize in order to achieve your requirement.

Let me start with your idea for adding an additional element in the visual tree and position it on top of RadGridView, over the update element. You can go with that idea, but keep in mind that you may have trouble position the extra element. To do so, you can try to get the GridViewCell which DataContext matches the updated data item and field, and use the code shown here to get the cell bounds. To get all GridViewCell elements, you can use the ChildrenOfType<T> extension method. This approach would be limited to the GridViewCells in the viewport. Also, this is prompt to errors.

The other idea with setting the values to "N/A" strings, I wouldn't say using different types in the same column is a good idea. That is because in this case, the column data operations like sorting, filtering and grouping will break. If you don't need these operations, you can try that idea.

What I could suggest you is to use the CellStyle property of the columns. This will allow you to data bind the Background of the GridViewCell element to an additional property of the data item. When the corresponding cell should be highlighted, you can update the additional property (on for each column) which will update the binding, thus the Background. You can data bind this with an IValueConverter. Using data bindings will have a slight impact (may be unnoticeable in this case) impact on the performance, but this approach should be quite reliable.

You can also explore the option of making the corresponding cells readonly.

I can suggest the same approach (binding the Background) for the RadTreeView control as well, but instead of CellStyle, there you can use the ItemContainerStyle property of RadTreeView.

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Bob
Top achievements
Rank 1
commented on 10 Dec 2023, 10:38 AM

1. sorry - i probably didnt explain properly - the idea was not to draw over the grid (i know that cant be done reliably) - I thought rather to insert into grid cell visual tree an element for the time it is needed and then remove it - to have better performance. it is same as to have a cell style with extra border and then change that style. only instead of changing the style - trying to manually manipulate all the cells visual trees.. I dont know if that is feasible or not and how the data binding would behave in that case.

2. that was my worry exactly - that string would throw off sort, filter, group. so you just confirmed it. that path is now out of question as i need sort and filter for sure

3. the cell style - yes thats an obvious solution which i was trying to avoid :) but since it seems the only way to do it correctly - i can only try and measure what kind of perf hit it gives (CPU and RAM) - because the trees can get very very large and with large amount of updates small %% can become a burden.

I will post some numbers once i get them..

Thank you for your help!

 
Martin Ivanov
Telerik team
commented on 11 Dec 2023, 10:46 AM

(1) You can do that but this solution won't be reliable. Basically, you can iterate all GridViewCell object using the ChildrenOfType<T> method with the RadGridView instance and then use the DataContext of the cell to access the data item and see if the cell should get updated. After that you can check what is inside of the visual tree of the GridViewCell (you can check its ControlTemplate for a reference) and insert a new visual there. However, because of the UI virtualization the GridViewCell visuals will be reused and moved around the viewport. So, the same cell visual can be displayed for a different column or row. Therefore, you will need to ensure that the inserted visual is removed afterwards. Also, timing issues could be possible, where the cell can be moved to another position after you show the extra visual and before hiding it.

(3) This would be the most reliable solution.

I also attached solution showing one way to implement the idea with the extra visuals displayed outside of RadGridView.

 

Tags
GridView TreeView
Asked by
Bob
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or