Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Grid Tech Support » Adding a count of the number of children to a row header Collapse All
Subject Author Date
Francois Bronsard Sep 18, 2009 - 10:20 AM

Hi,


When grouping rows, I would like to add to the HeaderCell an indication of the number of rows in that group.  Is that possible for bound or unbound grids and how?  What I would like to have is something like:


Name                 |   Address              |  tel


- John (3)


       John            |  1 road                   | 555


       John            |  2 road                   | 666


       John            |  3 road                   | 777


- Tom (1)


       Tom             | 1 str                      | 888


 


My question is how to add the "(3)" and "(1)" in the header cell.


Francois Bronsard

Technical Support Oct 19, 2009 - 8:24 AM

We are sorry but you cannot obtain this count right now not using internal properties, i.e. reflection. We’ll fix this issue in the next release which we plan for November.

As a workaround, you can use the following code:

int itemsCount = 0;

                GroupRow gr = cell.Row as GroupRow;
                if (gr != null)
                {
                    PropertyInfo pi = gr.GetType().GetProperty(
                        "MarkupTreeNode",
                        BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance);
                    SortGroupMarkupTreeNode node = pi.GetValue(cell.Row, null) as SortGroupMarkupTreeNode;
                    if(node != null)
                        itemsCount = node.DataItemCount;
                }

Technical Support Oct 16, 2009 - 7:56 AM

In order to display a custom content in the group row, you should implement a custom content viewer. Add a class to your project like as follows:

public class GroupRowViewer : ICellContentViewer
    {
        #region ICellContentViewer Members

        public System.Drawing.Size Measure(Cell cell, System.Drawing.Graphics g)
        {
            return Size.Empty;
        }

        public void Paint(Cell cell, System.Drawing.Graphics g)
        {
            using (StringFormat sf = new StringFormat())
            {
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Center;
                g.DrawString("This is custom text for group cell \"" + cell.DisplayValue + "\"", 
cell.GridControl.Font, SystemBrushes.ControlText, cell.ContentRectangle);
            }
        }

        #endregion
    }
Then add the following line after InitializeComponent() method :
boundGridControl1.CellStyles[typeof(GroupRowCellStyle)].CustomContentViewerType = typeof(GroupRowViewer);

Francois Bronsard Oct 16, 2009 - 2:40 PM

Very good! Thanks.

I have one more question though: How can I get the count of children rows? The data members "Rows" and "Children" associated with the group row are both null. If I use the debugger, I can see that there seem to be some internal private data member with the information I need (specifically, I can see that cell.Row.DataProvider.DataItemCount does countain the info I want but I don’t seem to be allowed to access that member.

Is there any other way to get that information, short of accessing the datatable and recalculating how many row match the display value of the cell?

Thanks

Francois Bronsard Oct 12, 2009 - 7:11 AM

Thanks but this is not quite what I meant: I want to change the text of the "row header" not the column header.  More precisely, suppose I have the table:


Name                 |   Address              |  tel


       John            |  1 road                   | 555

       John            |  2 road                   | 666

       John            |  3 road                   | 777

       Tom             | 1 str                       | 888


 and I group the table using the Name column.  So I end up with:


                  Address              |  tel

- John

                 1 road                   | 555

                 2 road                   | 666

                 3 road                   | 777

- Tom

                 1 str                      | 888


My question is: how could I change the text in the rowheaders "John" and "Tom" to indicate the number of children.  That is, I would like to have:


                  Address              |  tel

- John (3)

                 1 road                   | 555

                 2 road                   | 666

                 3 road                   | 777

- Tom (1)

                 1 str                      | 888


Is it possible? 


If it is only possible with an unbound grid, is there a simple way to populate an unboundgridcontrol with a datatable?

Technical Support Oct 1, 2009 - 6:27 AM

You can use the Column.HeaderText property to control the text displayed in the header cell.