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

Column width glitch

2 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 21 Jun 2013, 09:09 AM
Version: 2013.2.612.20
I noticed a strange behavior when trying to change the column width.
Just copy and paste the code below to get the same environment.

Hold the line between columns and move the cursor to the left a little. The first column will reduce its width inappropriately. The cursor remains in the correct position.

The result can be seen in the attached files before.png and after.png.

private void Form1_Load(object sender, EventArgs e)
{
GridViewTextBoxColumn col1 = new GridViewTextBoxColumn();
col1.HeaderText = "Stretch1";
    col1.MinWidth = 100;
    col1.Width = 200;
 
    GridViewTextBoxColumn col2 = new GridViewTextBoxColumn();
    col2.HeaderText = "Stretch2";
    col2.MinWidth = 100;
    col2.Width = 200;
 
    GridViewTextBoxColumn col3 = new GridViewTextBoxColumn();
    col3.HeaderText = "Static";
    col3.MaxWidth = 200;
    col3.MinWidth = 200;
    col3.Width = 200;
 
Telerik.WinControls.UI.RadGridView grid = new RadGridView();
grid.Location = new Point(0, 0);
grid.Size = new System.Drawing.Size(600, 100);
    grid.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            
    grid.MasterTemplate.Columns.AddRange(new GridViewDataColumn[] { col1, col2, col3});
 
    Controls.Add(grid);
}

2 Answers, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 25 Jun 2013, 09:19 AM
Hello Dominik,

Thank you for writing.


I have reviewed your case and was able to reproduce the issue. In this case when you set min and max width of the columns before actually adding the grid to the form it can not properly calculate the columns sizes. You should set the min and max width after you have added the grid, like this:
Controls.Add(grid);
col1.MinWidth = 100;
col2.MinWidth = 100;
col3.MaxWidth = 200;
col3.MinWidth = 200;

I hope this helps.
 
Regards,
George
Telerik
RadChart for WinForms is obsolete. Now what?
0
konrad
Top achievements
Rank 1
answered on 07 Aug 2013, 09:54 AM
Works like a charm!
Thanks for your help.
Tags
GridView
Asked by
konrad
Top achievements
Rank 1
Answers by
George
Telerik team
konrad
Top achievements
Rank 1
Share this question
or