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

Number of child elements in GridExpanderItem

1 Answer 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jan Pfeffer
Top achievements
Rank 1
Jan Pfeffer asked on 22 Jun 2011, 03:14 PM
Hey at Telerik

I subscibe to the event below and would like to show in the GridExpanderItem next to the plussign/minussign the number of child elements that exists in child GridViewTemplate.

All i can do is change the SignStyle, but there is no option for adding text.
I have tried to change the Text property, the size property and setting DrawTet to true, but with no luck.

Is there any way to add the text for instance "17" next to the plussign in GridExpanderItem ?

Perhaps it should be a setting that the number of child elements is shown near the expander.

I hope you can help me it's very important that the number is shown here to help people save time from expanding the element.

The tooltip just doesn't get the job done.

Sincerly Jan


private

 

void rgvEjendomme_ViewCellFormatting(object sender, CellFormattingEventArgs e)

 

{

 

GridGroupExpanderCellElement cell = e.CellElement as GridGroupExpanderCellElement;

 

 

if (cell != null && e.CellElement.RowElement is GridDataRowElement)

 

{

 

cell.Expander.Visibility = Telerik.WinControls.ElementVisibility.Visible;

cell.Expander.ToolTipText =
"Matrikler: " + ((Ejendom)e.Row.DataBoundItem).Matrikler.Count.ToString();

 

}

 

if (e.CellElement is GridDetailViewCellElement && e.CellElement.Children.Count != 0)

 

{

 

var pageView = e.CellElement.Children[0] as RadPageViewStripElement;

 

 

if (pageView == null)

 

{

 

return;

 

}

}

}

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 27 Jun 2011, 10:22 AM
Hi Jan Pfeffer,

You should create a custom expander cell element to achieve that:

public class MyGridGroupExpanderCellElement : GridGroupExpanderCellElement
{
    private LightVisualElement label;
    private StackLayoutElement stackLayout;
 
    public MyGridGroupExpanderCellElement(GridViewColumn col, GridRowElement row)
        : base(col, row)
    {
 
    }
 
    protected override void UpdateInfoCore()
    {
        base.UpdateInfoCore();
        this.label.Text = this.RowElement.RowInfo.ChildRows.Count.ToString();
    }
 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        this.Children.Remove(this.Expander);
 
        this.label = new LightVisualElement();
        this.label.DrawFill = false;
        this.label.DrawText = true;
 
        this.stackLayout = new StackLayoutElement();
        this.stackLayout.StretchVertically = true;
        this.stackLayout.Children.Add(this.Expander);
        this.stackLayout.Children.Add(this.label);
 
        this.Children.Add(this.stackLayout);
    }
 
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(GridGroupExpanderCellElement);
        }
    }
}

You should replace the default cell with that one in the CreateCell event:
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridGroupExpanderCellElement))
    {
        e.CellType = typeof(MyGridGroupExpanderCellElement);
    }
}

Notice that you should increase the width of the column:
this.radGridView1.TableElement.GroupIndent = 50;

All the best,
Svett
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Jan Pfeffer
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or