Edit item or subitem values of a selected listview item
This page looks like it would help you.
MaQleod
I'm a Software Quality Principal Engineer that specializes in Networking and hardware (with a strong emphasis on Unix/Linux systems). My background is in Telecom and Network troubleshooting. I am proficient in both Ethernet and Infiniband standards. I code primarily with Python, Autoit, C and and SQL in my spare time, but I like to occasionally tinker in other languages. My degree is in Classical Numismatics and Archaeology. I also keep a blog on investing. profile for MaQleod on Stack Exchange, a network of free, community-driven Q&A sites http://stackexchange.com/users/flair/343e8ac1ebe84dacb26151af03317dcd.png
Updated on June 04, 2022Comments
-
MaQleod almost 2 years
Ok, so I have a listview on one form, and when a button is pressed it opens up a new form with the contents of the selected listview item and it's subitems in a series of textboxes. The user can then change the data in the textboxes and either press save to make the changes or cancel to close the window. What command would I use to change the selected listview item and subitems to whatever is in the boxes?
this is the code that populates the boxes:
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim appeditcontents As String = main.passlist.SelectedItems(0).ToString Dim appstrlen As Integer = appeditcontents.Length() Dim apptotal As Integer = appstrlen - 16 Dim usereditcontents As String = main.passlist.SelectedItems(0).SubItems(1).ToString Dim userstrlen As Integer = usereditcontents.Length() Dim usertotal As Integer = userstrlen - 19 Dim passeditcontents As String = main.passlist.SelectedItems(0).SubItems(2).ToString Dim passstrlen As Integer = passeditcontents.Length() Dim passtotal As Integer = passstrlen - 19 appedit.Enabled = False appedit.Text = main.passlist.SelectedItems(0).ToString.Substring(15, apptotal) useredit.Text = main.passlist.SelectedItems(0).SubItems(1).ToString.Substring(18, usertotal) passedit.Text = main.passlist.SelectedItems(0).SubItems(2).ToString.Substring(18, passtotal) End Sub
Any pointers on cleaning up this code would probably help too.
-
MaQleod almost 15 yearswell, tried that, and it probably would work, except that it requires that items in the listview are selected when it performs the update, but when the edit form comes up the listview on the first form loses focus and the selected item is no longer selected and does not get updated
-
MaQleod almost 15 yearsnevermind, I had something formatted incorrectly, this is the solution: Private Sub saveedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveedit.Click Dim lvi As ListViewItem = main.passlist.SelectedItems(0) lvi.SubItems(0).Text = appedit.Text lvi.SubItems(1).Text = useredit.Text lvi.SubItems(2).Text = passedit.Text Me.Close() End Sub