how to create a multiline combobox

  • changing 1 month, 2 weeks ago

    I have a long string to be displayed in a combobox. But Multiline and WordWrap are not avilibale by ComboBoxCellType.
    I tried to create a new class using ComboBoxCellType, IWordWrapSupport, IMultilineSupport. But when I set combo.Multiline = true. It caused a System.StackOverflowException.

    How can I create a multiline combobox?

    BasicComboBoxCellType combo = new BasicComboBoxCellType();
    combo.Multiline = true;

    class BasicComboBoxCellType : ComboBoxCellType, IWordWrapSupport, IMultilineSupport
    {

    public bool Multiline
    {
    get
    {
    return Multiline;
    }

    set
    {
    Multiline = value;
    }
    }

    public bool WordWrap
    {
    get
    {
    return WordWrap;
    }

    set
    {

    WordWrap = value;
    }
    }
    }

  • 42p
    DeepakSharma1442p 1 month, 2 weeks ago

    Hi,

    You can create a custom ComboBoxCellType and override the PaintCell() function to wrap the text in Combo cell. Here is the code to do that:

    public class myComboCellType : ComboBoxCellType
        {
            public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
            {
                SolidBrush brushBack = new SolidBrush(appearance.BackColor);
                SolidBrush brushFore = new SolidBrush(appearance.ForeColor);
                StringFormat objStringFormat = new StringFormat();
                RectangleF rectfText = default(RectangleF);
               
                Rectangle rectButton = default(Rectangle);
                g.FillRectangle(brushBack, r);
                rectButton = new Rectangle(r.Right – 17, r.Y, 17, r.Height);
                ControlPaint.DrawComboButton(g, rectButton, ButtonState.Normal);
                    if (value!=null)
                {
                    objStringFormat.Alignment = StringAlignment.Near;
                    objStringFormat.LineAlignment = StringAlignment.Near;
    
                    rectfText = new RectangleF(r.X, r.Y, r.Width – 18, r.Height);
                    g.DrawString(value.ToString(), appearance.Font, brushFore, rectfText, objStringFormat);
                }
    
                //base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
            }
    
        }

    Thanks,
    Deepak Sharma

  • changing 1 month, 2 weeks ago

    Thank you very much DeepakSharma14. Your class works very well.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to create new topics.