
ListView - Editing a label as an icon is added
Private Sub Command1_Click()
Dim itmX As ListItem
Dim imgX As ListImage
'add the empty string
Set itmX = ListView1.ListItems.Add(, , "")
'assign an icon (optional)
itmX.SmallIcon = ImageList1.ListImages(1).Index
'if the item was added
If itmX.Index Then
'set focus to the listview
ListView1.SetFocus
'set the current item to the new index
Set ListView1.SelectedItem = itmX
'start the label edit
ListView1.StartLabelEdit
End If
'free the variables
Set itmX = Nothing
Set imgX = Nothing
End Sub
--
Randy Birch, MVP Visual Basic
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/
To assist in maintaining this thread for the benefit of
others, please post any response to this newsgroup.
Quote:
>Hello,
>Can someone give me an example of how to select listitem text for editing
after
>an icon has been added to a listview control?
>I have tried every possible way of doing this, but I only get as far as
having
>the icon be selected after adding it and then being able to edit it after
>clicking it. I want to mimic the behavior when creating a "New Folder" in
>Windows.
>I have set LabelEdit to lvwAutomatic. I have also tried using
StartLabelEdit
>and along with _BeforeLabelEdit but haven't had any luck.
>If someone could give me a quick example, I would appreciate it.
>Thanks!
>Anthony