|
-
Dec 14th, 2000, 09:36 AM
#1
Thread Starter
Addicted Member
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!
-
Dec 15th, 2000, 06:00 AM
#2
Fanatic Member
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]
-
Dec 15th, 2000, 09:53 AM
#3
Thread Starter
Addicted Member
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!
-
Dec 15th, 2000, 10:21 AM
#4
Fanatic Member
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]
-
Dec 15th, 2000, 01:37 PM
#5
Thread Starter
Addicted Member
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!
-
Dec 18th, 2000, 12:44 PM
#6
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|