Solved

treeview listview

Posted on 2000-03-26
4
270 Views
Last Modified: 2010-05-02
Like in Windows Explorer when we right click on a particular in the list view then it shows a popup when we select a Rename option then it allowed us to rename How we should do this using listview control Any property/method is there??
0
Comment
Question by:atreya
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
Try this
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  Dim strNewName As String
  If Button = vbRightButton Then
    If Not (ListView1.SelectedItem Is Nothing) Then
      strNewName = InputBox("Enter the new name:", "Item name", ListView1.SelectedItem)
      'do checking on the new value, maybe custom checking
      If strNewName = "" Then
        strNewName = ListView1.SelectedItem.Text
      End If
      ListView1.SelectedItem.Text = strNewName
    End If
  End If
End Sub
0
 
LVL 3

Accepted Solution

by:
Gordonp earned 20 total points
Comment Utility

the .StartLabelEdit method of the ListView control allows you to edit the listitem.

the AfterLabelEdit event then notifys you when the edit is complete, and what the new name is. You can also cancel the users change here.

Gordon
0
 

Author Comment

by:atreya
Comment Utility
hi
 Gordon.Thanks for ur help.
atreya
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
GordonP's solution only works if the Listview's LabelEdit property is set to true.. and you double click on the label.

To have your Rename work from a Popup Menu.. you have to set the focus back to the Listview and execute the Listview.StartLabelEdit method. The example below illustrates doing a label edit from another control.. <smile>.

In a Standard.Exe Project.. add a Listview and a Command button and then copy and paste the following into a code window.

<----- Code Begin ----->

Option Explicit

Private Sub Form_Load()
 
  ' Set the Labeledit property to manual
  ' So that the Listview only goes into rename mode when it is told so
  ' If you want double click to work set LabelEdit to lvwAutomatic  ListView1.LabelEdit = lvwManual  

  Dim itmWork As ListItem
  Dim i As Integer
  For i = 1 To 5   ' Add 5 Items
    Set itmWork = ListView1.ListItems.Add(, , "Text" & i)
  Next i

End Sub

Private Sub Command1_Click()
   
   ListView1.SetFocus
   ListView1.StartLabelEdit

End Sub

Private Sub Listview1_AfterLabelEdit _
(Cancel As Integer, NewString As String)
   
   If Len(NewString) = 0 Then
      Cancel = True
   End If

End Sub

<----- Code End ----->


0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now