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

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)