Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey

This has been very confusing to me and I can't think of any way to get this to work. I'm trying to make a simple instant messenging program as a summer project. For now I am working on the server part. I have the main form class (Form1) and a client handler class (ClientHandler). Once a user is connected, I want the client handler class to add the user name to a listbox on the main form called "lbUsers". In the beginning of this whole project, I thought that this would work:

 

'some code
Dim MainForm as New Form1()
MainForm.lbUsers.Add(Me.ClientID & " (" & UserName & ")")
'some code

 

but after trying it out, the code didn't add anything to the listbox. Does anybody know how to add an entry to a listbox from another class?

  • *Experts*
Posted

Well, first of all you add something to the listbox using its Items property.

Secondly, you are creating a new instance of the Form instead of referring to the one you already have. You are simply creating a new form and modifying it.

Posted
I took away the New in front of the Form1 and when the code executes I get an error saying "Object refrence not set to the instance of an object." Am I doing this all wrong? Sorry if this question is easy for you but I just don't know.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...