PDA

Click to See Complete Forum and Search --> : ListView API


miben
Dec 14th, 2000, 08:36 AM
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?

crispin
Dec 15th, 2000, 05:00 AM
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:


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

miben
Dec 15th, 2000, 08:53 AM
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!

crispin
Dec 15th, 2000, 09:21 AM
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 ;) )

miben
Dec 15th, 2000, 12:37 PM
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.

wasiq
Dec 18th, 2000, 11:44 AM
can anyone tell me how to get the text of the selected listview item using APIs