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

Grid view - Wrap text??

1 Answer 293 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 29 Mar 2010, 06:51 PM
Can you tell me how I get the grid view to wrap text and force the height of the cell to match the amount of text - IE exactly like in Excel where you select cell properties and select "wrap text"??

I really need a solution that is defined in the front end like the show/hide columns, expand widths etc, so the settings can be saved on the users end.

Can you tell me what i am looking for to achieve this?

Thanks





1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 01 Apr 2010, 12:31 PM
Hello James,

Yes, you can achieve a similar behavior when you set AutoSizeRows property of the grid to true. In addition, you should set WrapText property of the column that you want to wrap to true. The difference between RadGridView behavior and Excel is that in RadGridView you can wrap the text of all cells in a specified column while in Excel you can do this for a single cell. Presently, you cannot wrap the text of specified cell in RadGridView. You can use the following code snippet that creates additional item in the context menu which executes Wrap Text operation:
public GridForm()
{
    InitializeComponent();
 
    this.radGridView.AutoSizeRows = true;
    this.radGridView.ContextMenuOpening += new ContextMenuOpeningEventHandler(radGridView_ContextMenuOpening);
}
 
void radGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    GridDataCellElement dataCellElement =e.ContextMenuProvider as GridDataCellElement;
    if (dataCellElement != null)
    {
        RadMenuItem menuItem = new RadMenuItem("Wrap Text");
        menuItem.Click += new EventHandler(menuItem_Click);
        menuItem.Tag = dataCellElement.ColumnInfo;
        e.ContextMenu.Items.Add(menuItem);
    }
}
 
private void menuItem_Click(object sender, EventArgs e)
{
    RadMenuItem menuItem = sender as RadMenuItem;
    GridViewColumn column = menuItem.Tag as GridViewColumn;
    column.WrapText = true;
}

If you need further assistance, do not hesitate to write us back.

Sincerely yours,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or