Hi,

I am having throuble resetting my textboxes to nothing if the selection in the listview is nothing. I.e. when i select a record my textboxes are updated with teh selected data, but if nothing is selected after something is selected I would like to clear the textboxes to blank again.

Here is what i have. (i have the 3 extra sections in there and have been trying to get it to work so any help would be appreciated.

Private Sub ListViewSelection()

        If lvLocations.SelectedItems.Count > 0 Then

            Dim list As ListViewItem = lvLocations.SelectedItems(0)

            If list.SubItems.Count >= 1 Then
                If list.SubItems(1).Text <> "" Then
                    tbLineNo.Text = list.Index.ToString
                    tbID1.Text = list.Text
                    tbID2.Text = list.SubItems(1).Text
                    tbDPID.Text = list.SubItems(2).Text
                ElseIf list.SubItems(0).Text = "" Or list.SubItems(1).Text = "" Or list.SubItems(2).Text = "" Then
                    tbLineNo.Text = list.Index.ToString
                    tbID1.Text = ""
                    tbID2.Text = ""
                    tbDPID.Text = ""
                ElseIf list.Selected = False Then
                    tbLineNo.Text = list.Index.ToString
                    tbID1.Text = ""
                    tbID2.Text = ""
                    tbDPID.Text = ""
                ElseIf list.SubItems.Count = 0 Then
                    tbLineNo.Text = list.Index.ToString
                    tbID1.Text = ""
                    tbID2.Text = ""
                    tbDPID.Text = ""
                End If

            Else
                MsgBox("Incomplete")
            End If

        Else
            MsgBox("Incomplete")
        End If

    End Sub

You may add in the two Else(s) below _textbox.clear() . If you have several textboxes, you may want to create a procedure to do the same for all of them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.