Exclude particular cells from autosizing

4 posts, 0 answers
  1. Vladislav
    Vladislav avatar
    8 posts
    Member since:
    Jul 2016

    Posted 03 Aug Link to this post

    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?
  2. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 04 Aug Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Vladislav
    Vladislav avatar
    8 posts
    Member since:
    Jul 2016

    Posted 04 Aug Link to this post

    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.

  5. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 05 Aug Link to this post

    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.
Back to Top