views:

1611

answers:

1

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.

A: 

This page looks like it would help you.

Seba Illingworth
well, 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
nevermind, 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
MaQleod