RadVirtualGrid - CellValueNeeded doesn't support complex data types?

1 Answer 50 Views
VirtualGrid
Mihai Adrian
Top achievements
Rank 1
Iron
Mihai Adrian asked on 29 May 2024, 09:58 AM | edited on 29 May 2024, 10:59 AM

I have a list of <Data>, which I use to bind to a VirtualGrid
Data: 

   -Value [InnerData]: 

      -- Name [string]

      -- Description [string]

 

I use CellTemplateNeeded event handler to select a DataTemplate for the columns : 

private void RadVirtualGrid_CellTemplateNeeded(object sender, CellTemplateEventArgs e)

{

e.DataTemplate = this.Resources["Template"] as DataTemplate;

}

        <DataTemplate x:Key="Template">
            <StackPanel>
                <Label Content="{Binding Name}" />
                <Label Content="{Binding Description}" />
            </StackPanel>
        </DataTemplate>


And then I use CellValueNeeded to set the Value:

private void RadVirtualGrid_CellValueNeeded(object sender, CellValueEventArgs e)

{

e.Value = viewModel.List[e.RowIndex].Value;

}


So, basically I want to be able to "bind" an object to the Value of the Column.

Then, I want to display multiple properties of the object in the DataTemplate. 

 

It works fine with string data, for e.g.:

e.Value = viewModel.List[e.RowIndex].Value.Name

<Label Content="{Binding }" />


It doesn't work with objects:

e.Value = viewModel.List[e.RowIndex].Value

<Label Content="{Binding Name}" />

A workaround was to "bind" to a string which contains both properties, $"{name}--#--{description}", then use a converter to get the name and description and display it. 
But, I want to be able to pass an object, as I might need to display multiple properties. 

Is there a limitation here? Can you recommend a better way to do it? 

Thanks 

Dimitar
Telerik team
commented on 30 May 2024, 06:39 AM

Hi Mihai, 

Yes, this is how the VirtualGrid works at the moment, and using such objects is not supported. I wanted to ask why using such an appraoch instead of separate columns. This will break the, sorting filtering and editing is not how a grid is usually used. Have you considered using other controls for this? How many rows do you have in your actual project? 

I am looking forward to your reply.

1 Answer, 1 is accepted

Sort by
0
Mihai Adrian
Top achievements
Rank 1
Iron
answered on 04 Jun 2024, 08:19 AM

Hi Dimitar, 

We currently are using a GridView. The cells can be a text input / dropdown / attachments / etc. We need to bind to multiple properties to display the "read" cell, like title, value (image source - for attachments).

Currently we are facing some performance issues because we don't have virtualization enabled.

So the idea was to replace the GridView with the VirtualGrid, since it's more performant.

We have scenarios where the user can have 100 rows and 20 columns. I tried enabling the virtualization of GridView, but scrolling is very snappy and slow. With VirtualGrid is smoother.

Also, another question, is it possible to have the row height of a VirtualGrid set to Auto? So the cell adjust as needed? 

Dimitar
Telerik team
commented on 05 Jun 2024, 05:49 AM

Hi Mihai, 

Ok, I made a mistake, it turns out this is possible. I have attached an updated version of the project that shows how it can be achieved.  I have used a DataProvider in this case. 

Currently, you can only fit the column Width. We have a feature request for the row height on our feedback portal: VirtualGrid: Provide an option to fit the row height to content

Let me know if you have additional questions.

 

Tags
VirtualGrid
Asked by
Mihai Adrian
Top achievements
Rank 1
Iron
Answers by
Mihai Adrian
Top achievements
Rank 1
Iron
Share this question
or