RadGridView - Columns are fully collapsed on initial data load

0 Answers 82 Views
GridView
Matthew
Top achievements
Rank 1
Matthew asked on 18 Jun 2022, 06:45 PM | edited on 18 Jun 2022, 06:47 PM

Hi, please see images below and let me know if this is something that has been mentioned before.

When we first load our grid none of the columns are shown - see first screenshot (a).

After repopulating the dataset (ObservableCollection) with data, the columns are still all shrunk/collapsed - second image (b).

The blue column size stretcher has to be dragged to the right to reveal all the columns - third image (c).

It looks like it may be due to the container, Grid being set to * Width as we want the grid to fully populate the right of the screen, is there a way round this to have the radgridview work in this manner?

 

 

Matthew
Top achievements
Rank 1
commented on 18 Jun 2022, 10:30 PM

I have come up with a temporary solution - hopefully there is an easier one. But the following Helper Function appears to do the trick, though it does need to be rerun every time there is a change to the page size:


public static GridLength GetWidthOfParentColumn(UIElement element, int index)
        {
            var parent = VisualTreeHelper.GetParent(element);
            ColumnDefinitionCollection cdc = (ColumnDefinitionCollection)((Grid)parent).ColumnDefinitions;
            List<ColumnDefinition> ColDefs = new List<ColumnDefinition>();
            foreach (var itemColDefs in cdc)
            {
                ColDefs.Add(itemColDefs);
            }
            ColumnDefinition cd = ColDefs[index];
            return new GridLength((double)cd.ActualWidth, GridUnitType.Pixel);
        }

 

 
Martin Ivanov
Telerik team
commented on 22 Jun 2022, 11:31 AM

Can you send over some code showing how exactly do you setup the GridView and how the dataset is re-populated? Also, it will be useful if you show the layout that hosts the GridView.
Matthew
Top achievements
Rank 1
commented on 22 Jun 2022, 02:04 PM | edited

Hi Martin - a brief outline of the structure is:

MainWindow.xaml - a simple <frame to house main.xaml>

Main.xaml - <GRID> with 2 columns, col1 is auto width and holds a navigation tree in a radexpander, col 2 is '*' width is a <Grid> 1 row and 1 column both '*' height/width respectively - containing another <Frame> to be loaded with content depending on the navigation tree selection. (our selection here loads an InventoryManager.xaml)

InventoryManager.xaml - <grid> with 2 columns, col1 is similar to above , auto width and a radexpander with more options. Col 2 is '*' width and contains a UserControl (UCSystemPartGrid.xaml)

SystemPartGrid.xaml - <grid> with 3 rows and 1 column, originally I wanted this to be '*' but I am using auto width and the visualtreehelper function to resize this based on the column actual width of the parent grid in InventoryManager.xaml

The grid is a radgridview with raddatapager - using a local viewmodel linked to the user control where we load an observable collection into the datapager (note that we are utilising the telerik code to page this before grouping - cannot find the link for this at the moment).

Loading of data appears to be good, it's all there when I drag the blue line across - if I have the width set to 'auto' it is fine but the grid changes size based on what is presented. We would like it to just take up the rest of the space available.

I know this is bare bones code but it isn't really much more complicated than that. 

EDIT - If I put a dedicated <GRID> with 1 column and 1 row in Column 2 of InventoryManager.xaml 

and then bind the column width from the UCSystemPartGrid.xaml to this using:


<ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=Grid,AncestorLevel=1}, Path=ActualWidth}"></ColumnDefinition>

Then this does not cater for the expansion and closing of the two RadExpanders to the left, though using the helper function doesn't automatically cater for this either unless I tie the resize to the expanders open and close events - however everything is presented correctly on initial load.

With the addition of the dedicated grid the function is simpler now to get the grid actual width not finding the correct column.

 


        public static GridLength? GetWidthOfParentGrid(UIElement element)
        {
            GridLength? gridLength = null;
            Grid parent = VisualTreeHelper.GetParent(element) as Grid;
            gridLength = new GridLength((double)parent.ActualWidth, GridUnitType.Pixel);
            return gridLength;
        }

Matthew
Top achievements
Rank 1
commented on 22 Jun 2022, 03:17 PM | edited


OCViewSystemPart.Clear()

ctx = Utilities.NewContext();

List<ViewSystemPartForReqSerialNo> result = ctx.ViewSystemPartForReqSerialNo. Where(x => x.SystemId == mvm.CurrentSystem.Id && (SearchText.Length > 3 ? x.SearchableText.Contains(SearchText) : true) && ((splId == null || splId == new Guid()) || guids.Contains(x.LocationId)) ).Take(cnt).ToList(); ctx.Dispose(); OCViewSystemPart.AddRange(result.OrderBy(x => x.LocationBreadcrumb).ThenBy(x => x.Requirement.ThingName).ThenBy(x => x.SerialNo));


Martin, in answer to how the dataset is repopulated, we clear the collection and addrange with a new list collection from the backend - using EF and Sql Server
Matthew
Top achievements
Rank 1
commented on 23 Jun 2022, 04:48 PM

Hi Martin, 

I have some more insight into the issue - I created a new project with the basics and have included a function we use to calculate the correct pagesize for the datapager.

 

It appears that this is the code that is causing the collapsing columns -


public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
            GetPageSizeOfFrameworkElement(MainLayoutGrid, SystemPartGrid);
        }

        public static int GetPageSizeOfFrameworkElement(Grid layoutGrid, RadGridView radGridView)
        {
            int pageSize = 35;
            layoutGrid.Measure(new Size(double.MaxValue, double.MaxValue));
            double fixedHeight = 0;
            foreach (RowDefinition r in layoutGrid.RowDefinitions)
            {
                if (r.Height.Value != double.NaN)
                {
                    fixedHeight += r.Height.Value;
                }
            }
            double a = layoutGrid.RenderSize.Height - fixedHeight;
            double b = radGridView.RowHeight;
            if (layoutGrid.RenderSize.Height > 0)
            {
                pageSize = (int)(a / b) - 6;
                if (pageSize < 2)
                {
                    pageSize = 2;
                }
            }
            return pageSize;
        }

        private void SystemPartGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            GetPageSizeOfFrameworkElement(MainLayoutGrid, SystemPartGrid);
        }

Martin Ivanov
Telerik team
commented on 27 Jun 2022, 08:47 AM

Thank you for the provided code and description. I've tried following it in order to create a runnable project, but to no avail. I am still missing some portions of the code and I am not sure if I am setting up the layout properly, based on the description. This said, can you check the attached project and modify it so that it follows your setup and reproduces the issue?
Matthew
Top achievements
Rank 1
commented on 27 Jun 2022, 10:48 AM

Martin,

See attached - references may need resetting on load.

When you change the size of the window you will see that the columns disappear, it is not every time - though in our full project it is on load and every reload.

 

 

Martin Ivanov
Telerik team
commented on 29 Jun 2022, 01:12 PM

Thank you for the project. I can confirm that the issue appears also on my side. It seems that the Measure() call for the Grid panel in the GetPageSizeOfFrameworkElement is causing issues with the internally calculated sizes. To resolve this, avoid calling the Measure() method of the Grid panel when changing the PageSize. You can consider an alternative approach for getting ensuring the render size. Or if you insist on using the method, then you can use double.PositiveInfinity, instead of double.MaxValue for the measure size.

layoutGrid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

Can you please try this and let me know if it helps?

Matthew
Top achievements
Rank 1
commented on 29 Jun 2022, 01:43 PM

HI Martin - thank you, that is a useful solution!

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Share this question
or