Solved

treeview listview

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

809 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