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
Solved

treeview listview

Posted on 2000-03-26
4
273 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

828 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