Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help add data received from a TCP in each Columns

Help add data received from a TCP in each Columns

Scheduled Pinned Locked Moved Visual Basic
helpsysadmin
3 Posts 2 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Benjamindh
    wrote on last edited by
    #1

    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

    https://i.postimg.cc/hvkHf8V7/Screenshot-1.png

    Richard DeemingR 1 Reply Last reply
    0
    • B Benjamindh

      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

      https://i.postimg.cc/hvkHf8V7/Screenshot-1.png

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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))
      Next

      Me.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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      B 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        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))
        Next

        Me.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

        B Offline
        B Offline
        Benjamindh
        wrote on last edited by
        #3

        thank you very much it helped me thank you for your help

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups