Results 1 to 6 of 6

Thread: ListView API

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    I want to add an item to the ListView control
    using the API. I know I need to use LVM_INSERTITEM
    and fill in the LVITEM type, but I cant get it to work.
    Does anyone have an example of how to do this?
    Always looking for a better and faster way!

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Miben
    1 form,
    1 listview,
    1 imagelist(add some icons),
    1 Command Button.
    associate the listview with the imagelist,
    don't change the names of any of the above.
    then paste the following code into a form:

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LVM_FIRST = &H1000                     '// ListView messages
    Private Const LVM_INSERTITEMA = (LVM_FIRST + 7)
    
    
    
    Private Const LVIF_TEXT = &H1
    Private Const LVIF_IMAGE = &H2
    Private Const LVIF_PARAM = &H4
    Private Const LVIF_STATE = &H8
    Private Const LVIF_INDENT = &H10
    Private Const LVIF_NORECOMPUTE = &H800
    Private Const LVIS_FOCUSED = &H1
    Private Const LVIS_SELECTED = &H2
    Private Const LVIS_CUT = &H4
    Private Const LVIS_DROPHILITED = &H8
    Private Const LVIS_ACTIVATING = &H20
    Private Const LVIS_OVERLAYMASK = &HF00
    Private Const LVIS_STATEIMAGEMASK = &HF000
    
    
    Private Type LVITEM
        mask As Long
        iItem As Long
        iSubItem As Long
        state As Long
        stateMask As Long
        pszText As String
        cchTextMax As Long
        iImage As Long
        lParam As Long
        iIndent As Long
    End Type
    
    Private Function ListView_InsertItem(Hwnd As Long, pitem As LVITEM) As Long
        ListView_InsertItem = SendMessage(Hwnd, LVM_INSERTITEMA, 0, pitem)
    End Function
    
    
    Private Sub Command1_Click()
    Dim lpstrText As String
    Dim LItem As LVITEM
    lpstrText = "HELLO Miben"
    
    With LItem
        .mask = LVIF_TEXT Or LVIF_IMAGE Or LVIF_PARAM Or LVIF_STATE
        .state = 0
        .stateMask = 0
        .pszText = lpstrText
        .iImage = 1
    End With
    
    Debug.Print ListView_InsertItem(ListView1.Hwnd, LItem)
    
    
    End Sub
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    Yes! It works great! I am wondering if you can do the
    same with subitems...i havnt tried it but I am looking into it.

    I can now refresh only the portion of the screen that I want!
    When I add 6000 items or so, I can refresh then at any interval

    I want with no flickering or refreshing!
    Thank You Very Much!
    Always looking for a better and faster way!

  4. #4
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Yes miben you can add subitems, I don't have time today, but i'll give you some code monday (if you don't solve it in the meantime )

    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    I cant add multiple items using this method. It lets me add
    1 item great, but after that i get a memory read error.

    My guess is that I need to set the index for the new item, but I havnt figured this out yet.

    I appreciate all your help.
    Always looking for a better and faster way!

  6. #6
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    can anyone tell me how to get the text of the selected listview item using APIs

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