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

Set width of GridViewIndentColumn

4 Answers 248 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas Haeusler
Top achievements
Rank 2
Andreas Haeusler asked on 21 Feb 2016, 07:59 PM

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;
        }
    }
}

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Feb 2016, 03:17 PM
Hello Andreas,

Thank you for writing.

The 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
0
Andreas Haeusler
Top achievements
Rank 2
answered on 22 Feb 2016, 03:34 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Feb 2016, 01:47 PM
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 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
0
Andreas Haeusler
Top achievements
Rank 2
answered on 24 Feb 2016, 11:37 AM

Hello Dess,

 

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

Tags
GridView
Asked by
Andreas Haeusler
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Andreas Haeusler
Top achievements
Rank 2
Share this question
or