Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey, I have done a search in the forums and have not found a solution, so I thought I would ask and see if anyone knew what i needed to do to solve my problem. My problem is I have a listview with items and subitems and I want the user to be able to right click a selected listview item and hit edit contact which I have on the context menu and it load up another form I have and it will put all the the items from the selected listview item into a bunch of different text boxes.

 

Rampage<PS>

  • Leaders
Posted
What specifically is the problem? Or are you looking for a quick how-to? If the latter is the case, On the MouseDown (or MouseUp, I don't know which would be better) event, check which button was clicked (e.Button). If it was the right button, and there is an item selected (ListView.SelectedItems.Count = 1), pop your context menu up, and if they click "Edit Contact" populate your contact form with the subitems of your listview, show it, when they click OK, modify the selected item using the contents of the contact form.
[sIGPIC]e[/sIGPIC]
  • Leaders
Posted
This is one way to do it: Add a new constructor (Sub New) to your second form, which accepts a listview item. In the constructor call MyClass.New() to perform the normal initialization. Then set each textbox's .Text property to the appropriate subitem (ListViewItem.SubItems(index).Text [i think]). When the user clicks okay, set all the subitems to the modified textbox's text, and your changes should be reflected in the original listview.
[sIGPIC]e[/sIGPIC]
  • Leaders
Posted
sry to say this but i still don't understand what you are saying

 

Here. Modify this code as necessary and add it to your edit contact form. When you instantiate the form, rather than using the standared constructor [New frmEditContact], pass in the selected ListViewItem [New frmEditContact(lstContacts.SelectedItems(0))].

 

   'Assuming that your list view items have the following information: Name, Address, Phone Number
   Dim _Contact As ListViewItem
   Public Sub New(ByVal ContactInfo As ListViewItem)
       MyClass.New() 'Initialize
'
       _Contact = ContactInfo 'Retain a reference to the listview item
       'Get the info from the listviewitem and copy it to the textboxes
       txtName.Text = ContactInfo.SubItems(0).Text
       txtAdress.Text = ContactInfo.SubItems(1).Text
       txtPhoneNumber.Text = ContactInfo.SubItems(2).Text 'This should be validatad
'
       'This form should be shown using ShowDialog
   End Sub
'
   Private Sub btnOK_Click(ByVal Sender As Object, ByVal e As EventArgs) Handles btnOK.Click
       'Store the info back into the listview item
       _Contact.SubItems(0).Text = txtName.Text
       _Contact.SubItems(1).Text = txtAdress.Text
       _Contact.SubItems(2).Text = txtPhoneNumber.Text
       'Close the form
       Me.Close()
   End Sub

 

The form will be displayed with all the contact info, and when the user clicks the okay button (in the code above I named it btnOK) the info will be stored back to the ListViewItem.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...