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

Custom Adjust Cell Width on GridView

1 Answer 972 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 21 Jun 2019, 07:01 AM

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.

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Jun 2019, 10:53 AM
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.
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or