Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

treeview listview

Posted on 2000-03-26
4
Medium Priority
?
278 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 40 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

Independent Software Vendors: 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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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