Ticket Q510538
Visible to All Users

Expand GridControl group rows with details

created 12 years ago

I've been playing around with gridview.CollapseAllGroups, gridview.ExpandMasterRow, gridview.ExpandGroupRow and gridviewExpandAllGroups but simply can't find the right mix to do what I want.

I Have a grid control with master/detail releationship. The master view is grouped by default on a single field and the group header hiddin so the user can't change the grouping. (see attached screenshot).

What I want to have happen is the last group (Year :3 in the example) to be fully expanded a show in the ss by default. I'd like to then have it so when the user clicks on the Year: 1 or Year 2 rows all rows collapse and that year is fully expanded.

I've tired the following code in the master gridview mouse down event but it's not quite right. IE not all levels are expaned as seen the attached SS.

{
var hitInfo = gvPolicyTrans.CalcHitInfo(e.Location);
if (hitInfo.InRow && hitInfo.RowHandle < 0)
{
gvPolicyTrans.CollapseAllGroups();
gvPolicyTrans.ExpandMasterRow(hitInfo.RowHandle);
gvPolicyTrans.ExpandGroupRow(hitInfo.RowHandle, true);
gvTrans_Detail.ExpandAllGroups();
}

}

gvPolicyTrans is the master gridview and gvTrans_Detail is the child gird view.

Any help would be appreciated.

Thanks

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello,
I think that this task can be accomplished in an easier way. Handle the GridView.GroupRowExpanding event. In that event handler, collapse all groups and details, get count of rows within an expanded row and expand master rows via the GridView.ExpandMasterRow method:

C#
void gridView1_GroupRowExpanding(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) { gridView1.CollapseAllGroups(); gridView1.CollapseAllDetails(); int rowCount = gridView1.GetChildRowCount(e.RowHandle); for (int i = 0; i < rowCount; i++) gridView1.ExpandMasterRow(gridView1.GetChildRowHandle(e.RowHandle, i)); }

Please see the attached project for more information.
I hope you find this information useful and am looking forward to your results once you try this solution.

    Comments (3)

      Thanks,
      I knew there had to be a better way. It works perfectly. I just had to add the following line after I set the gridcontrol datasource to open the last group once the data is loaded.
       if (gricView1.RowCount > 0) gridView1.ExpandGroupRow(griceView1.RowCount * -1);
      Bob

        My last comment on how to expand the last group doesn't work if there is only 1 group. IE in my case I'm grouping on year and if all the data is in the same year the row count is for the rows in the master table not the number of groups. In all my looking I can't find a way to determine the number of groups. IE If I group by year and the date is spread across 5 years there are 5 groups and if all the data is in a single year there is just 1 group.
        Bob

        Andrew Ser (DevExpress Support) 12 years ago

          Hi,
          I have put your code after binding the GridControl to data and it works fine on my side (see the attachment). Please send us your project so that we can research it and find the cause of this issue.
          Regarding group rows. To count group rows, I suggest you call the GridView.CollapseAllGroups method and use the GridView.RowCount property.
          I hope to hear from you soon.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.