CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2001
    Posts
    26

    Divider in a listbox

    Hello

    I am looking for a divder in a listbox control or something, I wish to have the same look as in Filemanager in win9x where you can move the display area of files, dates and such.

    What control does that and how do I use it ?

    tia


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Divider in a listbox

    You can use the listview control for that. This can be found in the Windows Common Controls. You will need to set the display to report, and add columns to the control (using custom in the property window). Once you've done that, you will need to add ListItems to the list.

    private Sub Command1_Click()

    Dim LI as ListItem
    Dim T as Integer

    ListView1.ListItems.Clear
    for T=1 to 10
    set LI = ListView1.ListItems.Add Text:="Item " & T
    LI.SubItems(1) = "Item " & T & " Col 2"
    LI.SubItems(2) = "Item " & T & " Col 3"
    next T

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Divider in a listbox

    Here is a simple example of a Listview with three columns. It also supports sorting of those columns.
    Start a new project. Add a Listview (name it lv)
    Paste this code into the general declarations section of the form and run the program.
    The Form_Load event will setup and populate the listview. Click on column headers to Sort it.

    option Explicit

    public Function GetRandomNumber()
    Randomize
    GetRandomNumber = Int((99999 - 1 + 1) * Rnd + 1)
    End Function

    private Sub Form_Load()
    Dim NX as ListItem, i as Integer
    Dim Temp as string
    lv.ListItems.Clear
    lv.ColumnHeaders.Clear
    lv.ColumnHeaders.Add , "Col1", "Item", 500, lvwColumnLeft
    lv.ColumnHeaders.Add , "string", "string", 3000, lvwColumnRight
    lv.ColumnHeaders.Add , "Number", "Number", 2000, lvwColumnRight
    lv.View = lvwReport
    for i = 0 to 100
    Temp = string(25, " ")
    RSet Temp = Format(GetRandomNumber, "###,###,###.#0")
    set NX = lv.ListItems.Add(, "A" & Chr(i), i)
    NX.SubItems(1) = GetRandomNumber
    NX.SubItems(2) = Temp
    next i

    End Sub

    private Sub lv_ColumnClick(byval ColumnHeader as MSComctlLib.ColumnHeader)
    lv.SortKey = ColumnHeader.Index - 1
    If lv.SortOrder = 0 then
    lv.SortOrder = 1
    else
    lv.SortOrder = 0
    End If
    ' set Sorted to true to sort the list.
    lv.Sorted = true ' force list sort

    End Sub




    John G

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