Custom Adjust Cell Width on GridView

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    1 posts
    Member since:
    Jun 2019

    Posted 21 Jun Link to this post

    Regards!

    I'm trying adjust an columns of my GridView, but I don't know why it not change.

    I Want adjust the first column with AutoResize Fill, and de remain cells with BestFit:

                    LoadGrid();
                    InitializeTemplate();
                    
                    foreach (var Column in rgvHorasProveedores.MasterTemplate.Columns)
                    {
                        if (Column.Name != "Equipo") //Distinct to first column
                        {
                            if(Column.AllowResize == true)
                            Column.AllowResize = false;
                        }
                    }


                    //rgvHorasProveedores.Templates[0].BestFitColumns();
                    foreach (var Column in rgvHorasProveedores.Templates[0].Columns)
                    {
                        if (Column.Name != "Equipo")
                        {
                            
                            Column.AllowResize = false;
                        }
                    }
                    rgvHorasProveedores.Templates[0].AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
                    rgvHorasProveedores.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

    The level 2 (second template)it does not change and when reload thr grid, it lost the format.

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3282 posts

    Posted 25 Jun Link to this post

    Hello, Daniel,  

    The cells' width depends on the column's width. Note that RadGridView supports two ways to auto size the columns:
    - AutoSizeColumnsMode: columns can automatically fill the entire width of the grid. Just set the AutoSizeColumnsMode property of the desired template to GridViewAutoSizeColumnsMode.Fill.
    - Best fit: the column widths can be set to fit its content by using the GridViewTemplate.BestFitColumns or GridViewDataColumn.BestFit methods. This mode distributes algorithm that attempts to fit in the header text and column data for all visible rows.

    Mixing the two ways is not possible. However, you can best fit the columns and manually adjust the last (or any other) column's width according to the remaining space. You can subscribe to the RadGridView.SizeChanged event and recalculate the last (or any other) column's width.

    If you have hierarchy, it is necessary to access the Columns from the respective GridViewTemplate that you want to manage (e.g. MasterTemplate.Templates[0]). In case you are experiencing any further difficulties, it would be greatly appreciated if you can provide a sample project demonstrating the undesired behavior. Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    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.
Back to Top