Quick tutorial on ListView - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Quick tutorial on ListView

KDivad LeahcimKDivad Leahcim Posts: 3,948Member
Never used it before, but I think it's my best chance of getting what I want without writing a new control (again...).

Basically, I want a two-column, full-row-select listbox. Padding to make the second column is a PITA in a normal listbox while still using a decent font.

I don't need headers, sorting or anything else. I think I only need AddItem, RemoveItem, List(), ListIndex and ListCount. Obviously, those aren't the right names or I would have found them already... I have figure out how to make two columns, but it's the items part that is throwing me off.

Thanks,
KDL

Comments

  • DanElliottDanElliott Posts: 9Member
    You can make the FullRowSelect and HideColumnHeaders properties true at design time. If you're not using icons, you would use the report view.

    ListView1.View = lvwReport

    This will put items in the first column:

    ListView1.ListItems.Add , , "first"
    ListView1.ListItems.Add , , "second"
    ListView1.ListItems.Add , , "third"

    The first column is the list item. All other columns are subitems. To add a subitem, you have to specify ListItem's index ( row # -- in parenthesis below ) and the subitem's index
    ( the 1 after .Add below ). First subitem's index is 1.

    ListView1.ListItems(1).ListSubItems.Add 1, , "row 1 sub 1"
    ListView1.ListItems(2).ListSubItems.Add 1, , "row 2 sub 1"
    ListView1.ListItems(3).ListSubItems.Add 1, , "row 3 sub 1"

    Get the selected item's index:

    ListView1.SelectedItem.Index

    This will remove the selected item:

    ListView1.ListItems.Remove ListView1.SelectedItem.Index

    Here's how to get the list count:

    ListView1.ListItems.Count


    Simple, huh? Hope it helps.
    Dan
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : You can make the FullRowSelect and HideColumnHeaders properties true at design time. If you're not using icons, you would use the report view.
    :
    : ListView1.View = lvwReport
    :
    : This will put items in the first column:
    :
    : ListView1.ListItems.Add , , "first"
    : ListView1.ListItems.Add , , "second"
    : ListView1.ListItems.Add , , "third"
    :
    : The first column is the list item. All other columns are subitems. To add a subitem, you have to specify ListItem's index ( row # -- in parenthesis below ) and the subitem's index
    : ( the 1 after .Add below ). First subitem's index is 1.
    :
    : ListView1.ListItems(1).ListSubItems.Add 1, , "row 1 sub 1"
    : ListView1.ListItems(2).ListSubItems.Add 1, , "row 2 sub 1"
    : ListView1.ListItems(3).ListSubItems.Add 1, , "row 3 sub 1"
    :
    : Get the selected item's index:
    :
    : ListView1.SelectedItem.Index
    :
    : This will remove the selected item:
    :
    : ListView1.ListItems.Remove ListView1.SelectedItem.Index
    :
    : Here's how to get the list count:
    :
    : ListView1.ListItems.Count
    :
    :
    : Simple, huh? Hope it helps.
    : Dan
    :

    Great, thanks!
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : You can make the FullRowSelect and HideColumnHeaders properties true at design time. If you're not using icons, you would use the report view.
    :
    : ListView1.View = lvwReport
    :
    : This will put items in the first column:
    :
    : ListView1.ListItems.Add , , "first"
    : ListView1.ListItems.Add , , "second"
    : ListView1.ListItems.Add , , "third"
    :
    : The first column is the list item. All other columns are subitems. To add a subitem, you have to specify ListItem's index ( row # -- in parenthesis below ) and the subitem's index
    : ( the 1 after .Add below ). First subitem's index is 1.
    :
    : ListView1.ListItems(1).ListSubItems.Add 1, , "row 1 sub 1"
    : ListView1.ListItems(2).ListSubItems.Add 1, , "row 2 sub 1"
    : ListView1.ListItems(3).ListSubItems.Add 1, , "row 3 sub 1"
    :
    : Get the selected item's index:
    :
    : ListView1.SelectedItem.Index
    :
    : This will remove the selected item:
    :
    : ListView1.ListItems.Remove ListView1.SelectedItem.Index
    :
    : Here's how to get the list count:
    :
    : ListView1.ListItems.Count
    :
    :
    : Simple, huh? Hope it helps.
    : Dan
    :

    Syntax difference:

    LV.ListItems.Add , , "c1 i1"
    LV.ListItems.Add , , "c1 i2"
    LV.ListItems(1).SubItems(1) = "c2 i1"
    LV.ListItems(2).SubItems(1) = "c2 i2"

    That's what I ended up doing and it worked just fine. Perhaps it has to do with having a different version?

    Anyway, I seem to be missing a FullRowSelect property? This is a sort of clincher. Without it, I'll end up writing my own control.

    Thanks!
  • DanElliottDanElliott Posts: 9Member
    : Syntax difference:
    :
    : LV.ListItems.Add , , "c1 i1"
    : LV.ListItems.Add , , "c1 i2"
    : LV.ListItems(1).SubItems(1) = "c2 i1"
    : LV.ListItems(2).SubItems(1) = "c2 i2"
    :
    : That's what I ended up doing and it worked just fine. Perhaps it has to do with having a different version?
    :
    : Anyway, I seem to be missing a FullRowSelect property? This is a sort of clincher. Without it, I'll end up writing my own control.
    :
    : Thanks!
    :

    I have a FullRowSelect property, I'm using Microsoft Windows Common Controls 6.0

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : : Syntax difference:
    : :
    : : LV.ListItems.Add , , "c1 i1"
    : : LV.ListItems.Add , , "c1 i2"
    : : LV.ListItems(1).SubItems(1) = "c2 i1"
    : : LV.ListItems(2).SubItems(1) = "c2 i2"
    : :
    : : That's what I ended up doing and it worked just fine. Perhaps it has to do with having a different version?
    : :
    : : Anyway, I seem to be missing a FullRowSelect property? This is a sort of clincher. Without it, I'll end up writing my own control.
    : :
    : : Thanks!
    : :
    :
    : I have a FullRowSelect property, I'm using Microsoft Windows Common Controls 6.0
    :

    That's probably it then, I am using 5.0 instead. I don't currently have a copy of 6 on my system.
Sign In or Register to comment.