CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Posts
    97

    MutliColumn Listbox

    How on earth do you added data to the different columns of a multi column Listbox?

    Any example would help as I can't find any anywhere

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: MutliColumn Listbox

    A multi column list box has no vertical scroll bar.

    When a new item is added which would normally cause a vertical scroll bar to appear, it is instead inserted into a new column to the right.

    Try this : it's from MSDN and demonstrates the behaviour very well.

    Code:
       // Add items to the ListBox.
       for (int x = 0; x < 50; x++)
       {
          listBox1.Items.Add(string.Format("Items {0}", x));
       }
    
       // Display items in columns.
       listBox1.MultiColumn = true;
    
       // Determine the width of the items in the list to get the best column width setting.
       int width = (int) listBox1.CreateGraphics().MeasureString(
          listBox1.Items[listBox1.Items.Count -1].ToString(),
          listBox1.Font).Width;
    
       // Set the column width based on the width of each item in the list.
       listBox1.ColumnWidth = width;
    If you don't want behaviour like this then use a ListView in report mode instead.

    Darwen.
    Last edited by darwen; September 8th, 2004 at 08:13 AM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured