How to find whether group header is expanded?

6 posts, 0 answers
  1. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 23 Dec 2011 Link to this post

    I am trying to change the color of the header row when its in expanded mode. I tried the below code but didn't work.

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
            If TypeOf e.Item Is GridGroupHeaderItem Then
                Dim gpheader As GridGroupHeaderItem = CType(e.Item, GridGroupHeaderItem)
     
               If item.Selected Then
                 gpheader.BackColor = Drawing.Color.DarkSeaGreen
                End If
    End Sub

    Any other way?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Dec 2011 Link to this post

    Hello VIJAIANAND,

    <head runat="server">
        <title></title>
        <style type="text/css">
            .MyClass
            {
                background-color:Red !important;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                AllowSorting="true" ShowGroupPanel="true" GroupingEnabled="true" OnItemDataBound="RadGrid1_ItemDataBound">
                <MasterTableView DataKeyNames="ID,SrNo">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name1" UniqueName="Name" HeaderText="Name1">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowDragToGroup="true">
                </ClientSettings>
            </telerik:RadGrid>
        </div>
        </form>
    </body>
    </html>
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(System.Int32));
                dt.Columns.Add("Name", typeof(System.String));
                dt.Columns.Add("SrNo", typeof(System.Int32));
                dt.Rows.Add("1", "Name1", "1");
                dt.Rows.Add("2", "Name2", "2");
                dt.Rows.Add("3", "Name3", "3");
                dt.Rows.Add("4", "Name4", "4");
     
                RadGrid1.DataSource = dt;
            }
     
            protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridGroupHeaderItem)
                {
                    e.Item.CssClass = "MyClass";
                }
            }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 27 Dec 2011 Link to this post

    This is not right code or solution. There is no checking on whether group is expanded or not. You are only checking its a group row. Please don't put solutions without reading the questions.
  5. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 27 Dec 2011 Link to this post

    Hello VIJAIANAND,

    Have you looked at this code library thread? It points to a code library sample that should help you determine if the GroupRow Header is in an expanded state.
    ExpandCollapseGroupedGridOnDoubleClickingTheGroupHeader

    Hope this helps a bit.

    Cheers!
  6. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 27 Dec 2011 Link to this post

    That example gives an idea how I can do it but that incorporating "Dblclick" to invoke the expansion and identify its expanded or not. But a click event on the groupheader/groupsplitter column is already existing functionality. I thought it would be standalone property for the groupitem header to see whether expanded or not? 
  7. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 27 Dec 2011 Link to this post

    I was able to extract what I wanted it from the code snippet you provided and it works. Here you go, 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
           For Each grphdr As GridGroupHeaderItem In RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)
               If grphdr.Expanded Then
                   grphdr.BackColor = Drawing.Color.DarkSeaGreen
               End If
           Next
       End Sub
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017