Home Forums WinForms controls Xceed Grid for WinForms Hide Group Expand/Collapse Control

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16415 |

    Is it possible to hide (and therefore disable) the expand/collapse function on a group?

    I can’t find anything in either the Group or the GroupManagerRow which would handle this.

    Cheers,

    Imported from legacy forums. Posted by mattdwen (had 3488 views)

    User (Old forums)
    Member
    Post count: 23064

    There is no property you can set for this.  You will need to create your own GroupManagerRow, and override PaintForeground and OnClick() to accomplish this.

    e.g.:

    public class CustomGroupManagerRow : GroupManagerRow

    {

        // Initializes a new instance of the CustomGroupManagerRow class specifying the

        // template that will be used to create group manager rows.

        public CustomGroupManagerRow( CustomGroupManagerRow template )

            :

    base( template )

        {

        }

        public CustomGroupManagerRow()

        {

        }

        // Creates a clone of the CustomGroupManagerRow.

        protected override Row CreateInstance()

        {

            return new CustomGroupManagerRow( this );

        }

        // Paints the foreground of the CustomGroupManagerRow without

        //the +/- icon

        protected override void PaintForeground(GridPaintEventArgs e)

        {

            Rectangle

    m_buttonRectangle = new Rectangle( 0, 0, 0, 0 );

            //e.Graphics includes the expand/collapse button, so by using a 0 size rectangle, it will not be painted

            this.Theme.PaintGroup( e.Graphics, m_buttonRectangle, new GroupUIState( 0 ), 0 );

        }

        //Handle the click so it does not do anything.

        protected override void OnClick( EventArgs e )

        {

        }

    }

     

    Then use this in your code :

    private void Form1_Load(object sender, System.EventArgs e)

    {

        Group group1 = new Group();

        group1.GroupBy =

    “City”;

        CustomGroupManagerRow groupManagerRow1 = new CustomGroupManagerRow();

        group1.HeaderRows.Add( groupManagerRow1 );

        gridControl1.GroupTemplates.Add( group1 );

    }

    Or use the GroupAdded event so the same GroupManagerRow template is used when the user drags a column to the GroupByRow :

    private void Form1_Load(object sender, System.EventArgs e)

    {

        gridControl1.GroupAdded +=

    new GroupAddedEventHandler(gridControl1_GroupAdded);

    }

    private void gridControl1_GroupAdded(object sender, GroupAddedEventArgs e)

    {

       

    CustomGroupManagerRow groupManagerRow1 = new CustomGroupManagerRow();

        e.Group.HeaderRows.Clear();

        e.Group.HeaderRows.Add( groupManagerRow1 );

    }

     

    Imported from legacy forums. Posted by André (had 876 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks André,

    I’m finding it is hiding the entire contents of the header row.

    I was getting an error regarding ‘m_buttonRectangle’ not existing in the current context, which may have to do with me not inheritng the Xceed namespace, and declaring the all Xceed classes specifically (due to a conflict with existing DataRow objects).  As a result I added a Rectangle declartion in front of it, but I have a feeling I should be redefining an existing object, just not sure where it is.

     My mod as below:

                    Rectangle m_buttonRectangle = new Rectangle(0, 0, 0, 0);
                    this.Theme.PaintGroup(e.Graphics, m_buttonRectangle, new Xceed.UI.GroupUIState(0), 0);

    Imported from legacy forums. Posted by mattdwen (had 791 views)

    User (Old forums)
    Member
    Post count: 23064

    I like this. I also added an override to the prevent double clicking.

    However, I am finding that the Title no longer displays in the Group Manager Row; it is simply blank.

    Do you have the same issue?

    Thanks,

    Mark de Jeu
    mark@dejeu.com

    Imported from legacy forums. Posted by Mark (had 1111 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry, my mistake.  What happened is that I cut and pasted the code form a sample app I have, and this code was doing something else, and I forgot to copy some of the pieces required for this to work… [:P]

    So, for m_buttonRectangle, you need to declare it locally.  I have edited the post to correct the code.

    However, the other issue ( blank GroupManagerRow) it is a bit more complicated.  Because we override the PaintForeground so that base is not called, we have to also draw the text.  And in fact, we simply don’t need to draw the icon, so we can remove what’s in PaintForeground, and replace it with the following :

    protected override void PaintForeground(GridPaintEventArgs e)

    {

        StatelessVisualGridElementStyle style = this.GetDisplayVisualStyle( VisualGridElementState.Idle );

        using( StringFormat stringFormat = GetStringFormat( style ) )

        {

            using( Brush brush = new SolidBrush( style.ForeColor ) )

            {

                e.Graphics.DrawString(

    this.Title, this.Font, brush, e.ClientRectangle, stringFormat );

            }

        }

    }

     

    And you need to add the GetStringFormat() method :

    private StringFormat GetStringFormat( StatelessVisualGridElementStyle style )

    {

        Xceed.Grid.

    HorizontalAlignment horizontalAlignment = style.HorizontalAlignment;

        VerticalAlignment verticalAlignment = style.VerticalAlignment;

        bool wordWrap = style.WordWrap;

        bool clipPartialLine = style.ClipPartialLine;

        StringTrimming trimming = style.Trimming;

        if( horizontalAlignment == Xceed.Grid.HorizontalAlignment.Default )

            horizontalAlignment = Xceed.Grid.

    HorizontalAlignment.Left;

        if( verticalAlignment == VerticalAlignment.Default )

            verticalAlignment =

    VerticalAlignment.Top;

        StringAlignment vAlignment = StringAlignment.Near;

        StringAlignment hAlignment = StringAlignment.Near;

        switch( horizontalAlignment )

        {

            case Xceed.Grid.HorizontalAlignment.Left:

            {

                hAlignment =

    StringAlignment.Near;

                break;

            }

            case Xceed.Grid.HorizontalAlignment.Center:

            {

                hAlignment =

    StringAlignment.Center;

                break;

            }

            case Xceed.Grid.HorizontalAlignment.Right:

            {

                hAlignment =

    StringAlignment.Far;

                break;

            }

        }

        switch( verticalAlignment )

        {

            case VerticalAlignment.Top:

            {

                vAlignment =

    StringAlignment.Near;

                break;

            }

            case VerticalAlignment.Center:

            {

                vAlignment =

    StringAlignment.Center;

                break;

            }

            case VerticalAlignment.Bottom:

            {

                vAlignment =

    StringAlignment.Far;

                break;

            }

        }

        StringFormat stringFormat = null;

        try

        {

            StringFormatFlags stringFormatFlags = 0;

            if( !wordWrap )

                stringFormatFlags |=

    StringFormatFlags.NoWrap;

            if( clipPartialLine )

                stringFormatFlags |=

    StringFormatFlags.LineLimit;

            stringFormat =

    new StringFormat( stringFormatFlags );

            stringFormat.LineAlignment = vAlignment;

            stringFormat.Alignment = hAlignment;

            stringFormat.Trimming = trimming;

            stringFormat =

    this.CalculateStringFormat( stringFormat );

            return stringFormat;

        }

        catch

        {

            if( stringFormat != null )

                stringFormat.Dispose();

            throw;

        }

    }

     

    Note also that you may want to override OnDoubleClick so the group cannot be collapsed on a double click as well as a single click :

    protected override void OnDoubleClick( EventArgs e )

    {

    }

     

    Imported from legacy forums. Posted by André (had 475 views)

    User (Old forums)
    Member
    Post count: 23064

    Perfect for what I need!

    Thank you very much,

    Mark de Jeu
    mark@dejeu.com

    Imported from legacy forums. Posted by Mark (had 455 views)

    User (Old forums)
    Member
    Post count: 23064

    Excellent, works here too.

     

    Cheers,

    Imported from legacy forums. Posted by mattdwen (had 1639 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.