remove item without being selected only with the name
-
Hello everyone, I comment I have the following problem. It happens that I have this code where the information sent from a TCP is added, but I can't find a way to make it so that if a user leaves the application, it is removed from the listviem without having to be selected. only with the username that is in column 1
Protected Sub ActualizarTextoMensaje(ByVal sender As Object, ByVal e As System.EventArgs)
Dim HHusuario As String = "config\usuario.txt"
Dim Usuario As String
Usuario = System.IO.File.ReadAllText(HHusuario)
Dim line As String = ContenidoMensaje
Dim parts() As String = line.Split("|"c)
'ahora decodifico los bytes y los paso a el ListView
Dim item As New ListViewItem()
item.Text = parts(0)
If item.Text = Usuario Then
LNetgames.Items.Remove(item)
Else
For i As Integer = 1 To parts.Length - 1
item.SubItems.Add(parts(i))
Next
LNetgames.Items.Add(item)
End IfEnd Sub
-
Hello everyone, I comment I have the following problem. It happens that I have this code where the information sent from a TCP is added, but I can't find a way to make it so that if a user leaves the application, it is removed from the listviem without having to be selected. only with the username that is in column 1
Protected Sub ActualizarTextoMensaje(ByVal sender As Object, ByVal e As System.EventArgs)
Dim HHusuario As String = "config\usuario.txt"
Dim Usuario As String
Usuario = System.IO.File.ReadAllText(HHusuario)
Dim line As String = ContenidoMensaje
Dim parts() As String = line.Split("|"c)
'ahora decodifico los bytes y los paso a el ListView
Dim item As New ListViewItem()
item.Text = parts(0)
If item.Text = Usuario Then
LNetgames.Items.Remove(item)
Else
For i As Integer = 1 To parts.Length - 1
item.SubItems.Add(parts(i))
Next
LNetgames.Items.Add(item)
End IfEnd Sub
You should then first Find an item having the text of "username" in column 1. Then if it was found delete the item with the found item index. Note that there could be more than one item in your listview!