Solved

treeview listview

Posted on 2000-03-26
4
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2659825
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
ID: 2659847

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
ID: 2660070
hi
 Gordon.Thanks for ur help.
atreya
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2660112
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

718 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