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

AutoSizeColumnsMode Fill Issue

7 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gérald
Top achievements
Rank 2
Gérald asked on 03 Mar 2011, 11:55 AM
Hi,

I have a gridView with 2 columns, and the AutoSizeColumnsMode set to Fill.
The problem is that each time I refresh the data (in setting the datasource property with a new bindingList), the width of the second column is reduced by 1 pixel (the first column is growing).

Is this a known bug ?
Is there a workaround ?

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 03 Mar 2011, 12:27 PM
Hello,

Unless I have misunderstood I have been unable to replicate your issue. I have incuded a small sample below

Designer File
partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components;
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
        this.radButton1 = new Telerik.WinControls.UI.RadButton();
        ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();
        this.SuspendLayout();
        // 
        // radGridView1
        // 
        this.radGridView1.Location = new System.Drawing.Point(12, 12);
        this.radGridView1.Name = "radGridView1";
        this.radGridView1.Size = new System.Drawing.Size(260, 188);
        this.radGridView1.TabIndex = 0;
        this.radGridView1.Text = "radGridView1";
        // 
        // radButton1
        // 
        this.radButton1.Location = new System.Drawing.Point(142, 206);
        this.radButton1.Name = "radButton1";
        this.radButton1.Size = new System.Drawing.Size(130, 24);
        this.radButton1.TabIndex = 1;
        this.radButton1.Text = "ReBind and BestFit";
        this.radButton1.Click += new System.EventHandler(this.radButton1_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 240);
        this.Controls.Add(this.radButton1);
        this.Controls.Add(this.radGridView1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();
        this.ResumeLayout(false);
    }
    #endregion
    private Telerik.WinControls.UI.RadGridView radGridView1;
    private Telerik.WinControls.UI.RadButton radButton1;
}

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
  
    public partial class Form1 : Form
    {
        private BindingList<Person> people = new BindingList<Person>();
        private int counter = 1;
  
        public Form1()
        {
            InitializeComponent();
            this.radGridView1.AutoGenerateColumns = true;
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
  
        }
  
        private void LoadData()
        {
            int max = counter + 10;
            people.Clear();
            for (int i = counter; counter <= max; i++)
            {
                people.Add(new Person("Name " + counter.ToString(), "Description " + counter.ToString()));
                counter++;
            }
            this.radGridView1.DataSource = people;
        }
  
        private void radButton1_Click(object sender, EventArgs e)
        {
            LoadData();
  
            foreach (GridViewDataColumn column in this.radGridView1.Columns)
            {column.BestFit();}
  
            this.radGridView1.CurrentRow = this.radGridView1.Rows[0];
        }
    }
  
    public class Person
    {
        public Person(string name, string description)
        {
            this.Name = name;
            this.Description = description;
        }
  
        public string Name
        { get; set; }
  
        public string Description
        { get; set; }
    }

Let me know if you need further information
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 03 Mar 2011, 12:31 PM
Re-posting Form1.cs as I didn't include AutoSizeColumnsMode

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
  
    public partial class Form1 : Form
    {
        private BindingList<Person> people = new BindingList<Person>();
        private int counter = 1;
  
        public Form1()
        {
            InitializeComponent();
            this.radGridView1.AutoGenerateColumns = true;
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
  
        private void LoadData()
        {
            int max = counter + 10;
            people.Clear();
            for (int i = counter; counter <= max; i++)
            {
                people.Add(new Person("Name " + counter.ToString(), "Description " + counter.ToString()));
                counter++;
            }
            this.radGridView1.DataSource = people;
        }
  
        private void radButton1_Click(object sender, EventArgs e)
        {
            LoadData();
  
            foreach (GridViewDataColumn column in this.radGridView1.Columns)
            {column.BestFit();}
  
            this.radGridView1.CurrentRow = this.radGridView1.Rows[0];
        }
    }
  
    public class Person
    {
        public Person(string name, string description)
        {
            this.Name = name;
            this.Description = description;
        }
  
        public string Name
        { get; set; }
  
        public string Description
        { get; set; }
    }
0
Gérald
Top achievements
Rank 2
answered on 03 Mar 2011, 02:05 PM
Thank you for your response..

To reproduce the behaviour, set the ShowRowHeaderColumn property to False, and don't use the BestFit method :

private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.ShowRowHeaderColumn = false;
        }
  
private void radButton1_Click(object sender, EventArgs e)
        {
            LoadData();
            this.radGridView1.CurrentRow = this.radGridView1.Rows[0];
        }
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 03 Mar 2011, 02:14 PM
Hello,

Yes, I can replicate your issue. There would be two workarounds for this:

1: Continue to use the BestFitColumns method on each column
or
2: Provide a MaxWidth for the first column
LoadData();
this.radGridView1.Columns[0].MaxWidth = 60;

I hope that this helps, but if you require further information, please let me know
Regards,
Richard
0
Gérald
Top achievements
Rank 2
answered on 03 Mar 2011, 03:34 PM
Ok, the MaxWidth solution can fit my needs (with MinWidth to assure that the column won't grow)..

Thanks,
Gérald
0
Richard Slade
Top achievements
Rank 2
answered on 03 Mar 2011, 03:36 PM
You're welcome. Please remember to mark helpful posts as answer
Thanks
Richard
0
Stefan
Telerik team
answered on 07 Mar 2011, 04:09 PM
Hello guys, 

Thank you for writing.

Indeed, we currently experience such an issue. I have added it into out PITS system and we are going to address it in a future release. At this link you can subscribe for its status updates.

@Gérald, I have updated your Telerik points for this report.

Should you need anything else, do not hesitate to contact us.
 
Regards,
Stefan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Gérald
Top achievements
Rank 2
Answers by
Richard Slade
Top achievements
Rank 2
Gérald
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or