hierarchical data. BestFit, possible?

4 posts, 0 answers
  1. Czeshirecat
    Czeshirecat avatar
    66 posts
    Member since:
    Jun 2016

    Posted 01 Nov 2018 Link to this post

    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 :)

     

  2. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 01 Nov 2018 Link to this post

    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.
  3. Czeshirecat
    Czeshirecat avatar
    66 posts
    Member since:
    Jun 2016

    Posted 01 Nov 2018 in reply to Dimitar Link to this post

    That's great! many thanks.

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

  4. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 02 Nov 2018 Link to this post

    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.
Back to Top