Results 1 to 9 of 9

Thread: Display 2 data in listview control using winsock...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Display 2 data in listview control using winsock...

    ANYONE HELP?

    THIS THE CODE

    CLIENT:

    WINSOCK.SENDDATA = LOCALNAME
    WINSOCK.GETDATA = LOCALIP

    SERVER DATA ARRIVAL EVENT: ???

    WHAT CODE WILL I USE TO SEPARATE THE DATA CAME FROM THE CLIENT USING LISTVIEW CONTROL....

    LIKE THIS ONE

    [PCNAME]FIRST COLUMN IN LISTVIEW CONTROL

    [IPADD]SECOND COLUMN IN LISTVIEW CONTROL

    WHAT THE SOURCE CODE FOR THIS PROBLEM...

    PLEASE I'M IN RUSH COZ I'M USING IT AS A THESIS

    THANK..

    "Program KiRa"

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Display 2 data in listview control using winsock...

    Here''s what you need to do.

    Step 1, turn off caps lock. This part is essential for the code to work.

    Step 2
    WHAT CODE WILL I USE TO SEPARATE THE DATA CAME FROM THE CLIENT USING LISTVIEW CONTROL....
    ListView can't do or separate anything on it's own, it can only display what you tell it to. You will have to sort the data yourself before you 'give' it to the ListView. Doing that depends on the format and structure of the data you are receiving, but most likely you will be doing it using standard string manipulation functions (Split, InStr, Left$, Right$, Mid$, Len...)

    Regarding ListView display style, right click on it in Design mode, go to Properties, change the View to Report style, and add two Columns to it. Then you can use code like this to add items to it:

    Code:
    ListView1.ListItems.Add, , "Sample text in column 1"
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add, , "Item in col 2"
    Last edited by baja_yu; Aug 10th, 2010 at 01:53 PM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Re: Display 2 data in listview control using winsock...

    oh sorry about the capslock...

    thanks for the idea....i almost got the listview properties...thx

    in the data arrival event what code will i use to split the data?

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Display 2 data in listview control using winsock...

    oh sorry about the capslock...
    Don't worry about it

    Depends on how the data is formated. Post an example of the raw data you get and I'll help you with extracting data from it.

    For example, if you get "somename/someip" you could simply use Split function passing "/" as the token.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Re: Display 2 data in listview control using winsock...

    ok like this one.....

    'the client will send the name and ip of the PC
    Private Sub cmdSend_Click()
    Dim PC As String
    Dim IP As String

    PC = SckUDP.LocalHostName
    IP = SckUDP.LocalIP
    SckTCP.SendData PC & "|" & IP

    'then the server will recieve the MSG
    Private Sub SckTCP_DataArrival(ByVal bytesTotal As Long)
    Dim MSG As String

    SckTCP.GetData MSG, vbString

    "whats next?"
    the ouptut should be like this:

    ListView1.ListItems.Add = PCname
    ListView1.ListItems.subitems(1) = IPaddress

    what am i gonna do?

  6. #6
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Display 2 data in listview control using winsock...

    What is the exact data you get back?

    What would be displayed if you did

    MsgBox MSG

    after the GetData call?

    If I'm correct you are making the server and client app, and the client is sneding the name and IP with this: SckTCP.SendData PC & "|" & IP
    Then the server is receiving it with: SckTCP.GetData MSG, vbString

    If that's correct the server would receive a string like this: SomeName|127.0.0.1, for example. If that is so, you can do this after the GetData call

    Code:
    Dim strRecData () As String
    
    strRecData = Split(MSG, "|")
    
    ListView1.ListItems.Add, , strRecData(0) 'name
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add, , strRecData(1) 'IP

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Re: Display 2 data in listview control using winsock...

    hmmm, gonna check this out.... thx

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Re: Display 2 data in listview control using winsock...

    it works thanks a lot oh btw, is this can be used as vice versa?
    like client to server and server to client?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    30

    Re: Display 2 data in listview control using winsock...

    oh i forgot something, when the client is disconnected

    what code will i used to refresh the listview control...?

    like this...

    when the client was disconnected,

    the client will disappeared from the listview of the server....

    is it possible?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width