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

Exclude particular cells from autosizing

3 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vladislav
Top achievements
Rank 1
Vladislav asked on 03 Aug 2016, 01:39 PM
Hello, I have a grid view that have a header and 3 rows that are in effect also a header information so they are not editable. Now, the issue is that I want the particular column to resize, but to exclude width of the cells in first three rows from autosizing. In short I want the autosize to depend only on values input in the rows after the first three. How to do this? I already use cellFormatting event to color cells in first three rows so I guess I cannot use this event to prevent resize caused by the values in first three rows. Is there something like single cellResize event or something?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Aug 2016, 08:31 AM
Hello Vladislav,

In this case, you should use the CellFormating event and strip the text in the first columns:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.ColumnIndex <3 && e.CellElement.Text != null)
    {
        if (e.CellElement.Text.Length >5)
        {
            e.CellElement.Text = e.CellElement.Text.Substring(0, 5);
        }
       
    }
    
}

I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Vladislav
Top achievements
Rank 1
answered on 04 Aug 2016, 01:28 PM

You probably meant

if (e.RowIndex <3 && e.CellElement.Text != null)

But, anyway, this has has two drawbacks, autoellipsis is missing, and the text inside these substringed cells is kept to 5 chars even though the column width is increased in the meantime manually in the UI or by Autosize caused by editing the value of some other cell. It should show complete text now since it can fit.

0
Dimitar
Telerik team
answered on 05 Aug 2016, 12:12 PM
Hi Vladislav,

In this case, you can disable the TextWrap for the first 3 rows:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.RowIndex <3 && e.CellElement.Text != null)
    {
        e.CellElement.TextWrap = false;
    }
}

I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Vladislav
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Vladislav
Top achievements
Rank 1
Share this question
or