Auto column size

5 posts, 1 answers
  1. Pro
    Pro avatar
    3 posts
    Member since:
    Feb 2015

    Posted 06 Mar 2015 Link to this post

    How to do that would automatically change the size of the column height, depending on the amount of text in it?
  2. Answer
    Mahmoud
    Mahmoud avatar
    10 posts
    Member since:
    Mar 2015

    Posted 09 Mar 2015 Link to this post

    there is property "AutoSizeRows" = True
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Mar 2015 Link to this post

    Hi guys,

    That is correct, the AutoSizeRows is what you need in order to size your rows according to their content. 

    @Mahmoud - thank you for your community effort. I have updated your Telerik Points as a token of appreciation.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 15 Mar 2015 Link to this post

    If the entered text is not multiline it does not work
  6. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 18 Mar 2015 Link to this post

    Hello Stas,

    Thank you for writing.

    You would also need to handle the CellFormatting event of the grid and set the TextWrap property of the CellElement argument to true. Please see my code snippet below:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
      
            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("TextBoxColumn");
            radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
      
            this.radGridView1.Rows.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor non nibh sit amet tempus. Suspendisse potenti.");
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.AutoSizeRows = true;
      
            this.radGridView1.CellFormatting += radGridView1_CellFormatting;
        }
      
        private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement is GridDataCellElement && e.CellElement.ColumnInfo.Name == "TextBoxColumn")
            {
                e.CellElement.TextWrap = true;
            }
        }
    }

    I am also sending you gif file of the result on my end.

    I hope this information is useful. Should you have further questions please do not hesitate to write back.


    Regards,
    Hristo Merdjanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready