Set width of GridViewIndentColumn

5 posts, 0 answers
  1. Andreas Haeusler
    Andreas Haeusler avatar
    25 posts
    Member since:
    Nov 2009

    Posted 21 Feb Link to this post

    Hello,

     

    is there a way to change the width of specific GridViewIndentColumns? I'm trying to hide the very first IndentColumn in a Grid with 2 group levels. So far i tried changing one (or a combination) of the following 3 properties without any success:

    private void GridView_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        var indentColumn = e.CellElement.ColumnInfo as GridViewIndentColumn;
        if (indentColumn != null)
        {
            switch (indentColumn.IndentLevel)
            {
                case 0:
                    e.CellElement.Size = new Size(0,e.CellElement.Size.Height);
                    indentColumn.Width = 0;
                    e.CellElement.Visibility = ElementVisibility.Collapsed;
                    return;
                case 1:
                    indentColumn.Width = 20;
                    e.CellElement.Size = new Size(20, e.CellElement.Size.Height);
                    e.CellElement.Visibility = ElementVisibility.Visible;
                    break;
            }
        }
    }

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 22 Feb Link to this post

    Hello Andreas,

    Thank you for writing.

    The indent cell's width can be controlled by the RadGridView.TableElement.GroupIndent property. However, it will affect all indent cells. Note that the grid groups are nested and RadGridView performs its layout considering the specified value for the RadGridView.TableElement.GroupIndent property. Hence, you can't hide one of the indent columns, because it won't be possible to expand/collapse the group. 

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andreas Haeusler
    Andreas Haeusler avatar
    25 posts
    Member since:
    Nov 2009

    Posted 22 Feb in reply to Dess Link to this post

    Hello Dess,

     

    i know about the GroupIndent property -but as you said, this is a global setting.

    To expand/collapse groups with hidden IndentColumns I simply subscribe to the Gridview_CellClick of the GridViewGroupRowInfos and expand and collapse there.So that is no problem. 

    private void GridView_CellClick(object sender, GridViewCellEventArgs e)
    {
        if (e.Row is GridViewGroupRowInfo)
        {
            e.Row.IsExpanded = !e.Row.IsExpanded;
        }
    }

     

    I'm developing for a scenario with very limited screen real estate, so the RowHeaderColumn (done) and (preferably only the first) IndentColumn have to go. If you say it is not possible, I will have to decide which is the lesser evil: wasting space with the first IndentColumn or sacrificing readability by hiding all IndentColumns (hence making it hard to identify which group level a row belongs to).

     

    Regards,

    Andreas

  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Feb Link to this post

    Hello Andreas,

    Thank you for writing back. 

    In order to achieve different group indent for the different group levels, you can use a custom CellElementProvider where in its GetElementSize method, you can specify the width considering the group level. Here is a sample code snippet:
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.TableElement.CellElementProvider = new CustomCellElementProvider(this.radGridView1.TableElement);
        this.radGridView1.CellClick += radGridView1_CellClick;
    }
     
    private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
    {
        GridViewGroupRowInfo groupRow = e.Row as GridViewGroupRowInfo;
        if (groupRow.GroupLevel == 0)
        {
            e.Row.IsExpanded = !e.Row.IsExpanded;
        }
    }
     
    public class CustomCellElementProvider : CellElementProvider
    {
        GridTableElement rowView;
     
        public CustomCellElementProvider(GridTableElement rowView) : base(rowView)
        {
            this.rowView = rowView;
        }
     
        public override SizeF GetElementSize(GridViewColumn item)
        {
            float width = item.Width;
     
            if (item is GridViewRowHeaderColumn)
            {
                width = rowView.RowHeaderColumnWidth;
            }
            else if (item is GridViewIndentColumn)
            {
                GridViewIndentColumn indentColumn = item as GridViewIndentColumn;
                if (indentColumn.IndentLevel == 0)
                {
                    width = 1;
                }
                else if (indentColumn.IndentLevel == 20)
                {
                    width = 30;
                }
                else
                {
                    width = rowView.GroupIndent;
                }
            }
     
            if (width < 0)
            {
                width = DefaultElementSize.Width;
            }
     
            if (item is GridViewGroupColumn)
            {
                ColumnGroupRowLayout layout = rowView.ViewElement.RowLayout as ColumnGroupRowLayout;
                if (layout != null)
                {
                    ColumnGroupsCellArrangeInfo arrangeInfo = layout.GetColumnData(item);
                    if (arrangeInfo != null)
                    {
                        width = arrangeInfo.Bounds.Width;
                    }
                }
            }
     
            return new SizeF(width, 0);
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Andreas Haeusler
    Andreas Haeusler avatar
    25 posts
    Member since:
    Nov 2009

    Posted 24 Feb in reply to Dess Link to this post

    Hello Dess,

     

    this is working perfectly! Thank you very much, once again. :-)

Back to Top
UI for WinForms is Visual Studio 2017 Ready