Help add data received from a TCP in each Columns
-
Hello everyone, I have the following problem. It happens that I sent some data through TCP and I receive it, but it happens that this data is all added in a single column.
Public Function Rutina()
Do
If Ejecuto = True Then
Exit Do
End If
'check if tcp has pending connections
If TCP.Pending = True Then
'If it has Pending, I assign it to the client of the server that will listen
TCPSERVERCLI.Client = TCP.AcceptSocket
End If
If TCPSERVERCLI.Connected = True Then
'Indicates that there is data pending collection
If TCPSERVERCLI.Available > 0 Then
Dim DataBytes(1000) As Byte
'Now the decoder
Dim decode As New ASCIIEncoding
TCPSERVERCLI.Client.Receive(DataBytes)
'now I decode the bytes and pass them to the ListView
Me.LNetgames.Items.Add(decode.GetString(DataBytes))
End If
End If
Loop
End Function -
Hello everyone, I have the following problem. It happens that I sent some data through TCP and I receive it, but it happens that this data is all added in a single column.
Public Function Rutina()
Do
If Ejecuto = True Then
Exit Do
End If
'check if tcp has pending connections
If TCP.Pending = True Then
'If it has Pending, I assign it to the client of the server that will listen
TCPSERVERCLI.Client = TCP.AcceptSocket
End If
If TCPSERVERCLI.Connected = True Then
'Indicates that there is data pending collection
If TCPSERVERCLI.Available > 0 Then
Dim DataBytes(1000) As Byte
'Now the decoder
Dim decode As New ASCIIEncoding
TCPSERVERCLI.Client.Receive(DataBytes)
'now I decode the bytes and pass them to the ListView
Me.LNetgames.Items.Add(decode.GetString(DataBytes))
End If
End If
Loop
End FunctionBecause that's precisely what you've told it to do! You need to split the string and add the elements to the columns:
Dim line As String = decode.GetString(DataBytes)
Dim parts() As String = line.Split("|"c)Dim item As New ListViewItem()
item.Text = parts(0)
For i As Integer = 1 To parts.Length - 1
item.Subitems.Add(parts(i))
NextMe.LNetgames.Items.Add(item)
NB: According to your screenshot, your text starts with the
|
character. You may need to adjust the indices on the array to skip the blank first element:item.Text = parts(1)
For i As Integer = 2 To parts.Length - 1
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Because that's precisely what you've told it to do! You need to split the string and add the elements to the columns:
Dim line As String = decode.GetString(DataBytes)
Dim parts() As String = line.Split("|"c)Dim item As New ListViewItem()
item.Text = parts(0)
For i As Integer = 1 To parts.Length - 1
item.Subitems.Add(parts(i))
NextMe.LNetgames.Items.Add(item)
NB: According to your screenshot, your text starts with the
|
character. You may need to adjust the indices on the array to skip the blank first element:item.Text = parts(1)
For i As Integer = 2 To parts.Length - 1
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
thank you very much it helped me thank you for your help