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

hierarchical data. BestFit, possible?

3 Answers 22 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Czeshirecat
Top achievements
Rank 1
Czeshirecat asked on 01 Nov 2018, 10:25 AM

Ive got 2 questions.

1)When I select a page of the grid, then in the OnCellValueNeeded event, if that page has no table of data then I call function "AskForData" which uses an event to run a sql  query to read in 100 records to fill the table.

My call to Grid.VirtualGridElement.BestFitColumns(); is the last line of the AskForData() function as I didn't really know where else to put it, it seems to work. But at that moment of time, the cells haven't been formatted. Is there a recommended event I should trap?

2) I've set up my grid to use a hierarchical/child grid for displaying some data using the help document https://docs.telerik.com/devtools/winforms/virtualgrid/hierarchical-virtual-grid/hierarchical-data

Grid.VirtualGridElement.BestFitColumns seems to affect the masterviewinfo but not the child view info. Is there a way of accessing that to get bestfit on child columns?

thanks :)

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 01 Nov 2018, 11:55 AM
Hello Claire,

It would be better to use the PageIndexChanging event to get the data. This way when the CellValueNeeded is fired you will have the new data. Then you can use the PageChanged event to call the BestFitColumns method. For example:
public RadForm1()
{
    InitializeComponent();
 
    radVirtualGrid1.VirtualGridElement.PageIndexChanging += VirtualGridElement_PageIndexChanging;
    radVirtualGrid1.PageChanged += RadVirtualGrid1_PageChanged;
}
 
private void RadVirtualGrid1_PageChanged(object sender, Telerik.WinControls.UI.VirtualGridEventArgs e)
{
    radVirtualGrid1.BestFitColumns();
}
 
private void VirtualGridElement_PageIndexChanging(object sender, Telerik.WinControls.UI.VirtualGridPageChangingEventArgs e)
{
    source = GetData(e.NewIndex, 20);
 
}

2. You can use the RowExpanded event for this. Here is the code:
private void RadVirtualGrid1_RowExpanded(object sender, VirtualGridRowExpandedEventArgs e)
{
    radVirtualGrid1.VirtualGridElement.BestFitColumns(e.ChildViewInfo);
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Czeshirecat
Top achievements
Rank 1
answered on 01 Nov 2018, 02:27 PM

That's great! many thanks.

The "radVirtualGrid1.VirtualGridElement.BestFitColumns(e.ChildViewInfo);" doesn't appear to work, sadly. But the rest was very helpful :)

0
Dimitar
Telerik team
answered on 02 Nov 2018, 09:34 AM
Hello Claire,

I have tested this using the same approach as in the article and it works on my side. For convenience, I prepared a small sample, based on the information that you provided so far and attached it to this thread. Could you please check it and let me know how it differs from your real setup? 

Thank you in advance for your patience and cooperation. 

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
VirtualGrid
Asked by
Czeshirecat
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Czeshirecat
Top achievements
Rank 1
Share this question
or