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

Auto column size

4 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pro
Top achievements
Rank 1
Pro asked on 06 Mar 2015, 07:46 PM
How to do that would automatically change the size of the column height, depending on the amount of text in it?

4 Answers, 1 is accepted

Sort by
0
Accepted
Mahmoud
Top achievements
Rank 1
answered on 09 Mar 2015, 10:33 AM
there is property "AutoSizeRows" = True
0
Stefan
Telerik team
answered on 10 Mar 2015, 12:38 PM
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.

 
0
Stas
Top achievements
Rank 1
answered on 15 Mar 2015, 12:45 PM
If the entered text is not multiline it does not work
0
Hristo
Telerik team
answered on 18 Mar 2015, 01:19 PM
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.

 
Tags
GridView
Asked by
Pro
Top achievements
Rank 1
Answers by
Mahmoud
Top achievements
Rank 1
Stefan
Telerik team
Stas
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or