Jul 15, 2015 11:38 PM
(This post was last modified: Jul 16, 2015 03:07 AM by Vrekt.)
UPDATE: Thanks everybody who replied and tried to help me, I learned some new things today :).
Here is how I solved the problem.
NOTE: all this code is done in the main form containing the listbox.
Thanks to Odus btw :P
Firstly in your other class containing the thread put
Secondly the function to invoke the listbox:
^^ Does not have to be public I just did that because I'm a skid and thought I needed it....
Alright great! Now we need some variables..
Awesome. So now create a new sub named "additemtolistbox" (or whatever you prefer)
In this sub put this:
NOTE: Option Strict and Explicit is on.
Alright 2 more things now.
We basically want this sub to loop, so the lazy way to do so is call the sub in form paint event.
So now in your other thread in the other class, simply put
That should give you a basic idea of how this would work. This code is probably buggy, but I hope it helps some of you :)
Here is how I solved the problem.
NOTE: all this code is done in the main form containing the listbox.
Thanks to Odus btw :P
Firstly in your other class containing the thread put
Code
Public Shared flag as ObjectSecondly the function to invoke the listbox:
Code
Public Delegate Sub DelUpdateListBox(lb As ListBox, item As String)
Public Sub UpdateListBox(lb As ListBox, item As String)
If Me.InvokeRequired Then
Me.Invoke(New DelUpdateListBox(AddressOf UpdateListBox), New Object() {lb, item})
Else
lb.Items.Add(item)
End If
End Sub^^ Does not have to be public I just did that because I'm a skid and thought I needed it....
Alright great! Now we need some variables..
Code
' // We are going to be doing this on another sub, so to stop it from writing the item multiple times we need this.
Private written As Boolean = False
' comparing the lastitem with the current to make sure there not the same.
Private lastline As StringAwesome. So now create a new sub named "additemtolistbox" (or whatever you prefer)
In this sub put this:
Code
If yourotherclass.flag Is Nothing Then
Return
End If
If Not yourotherclass.flag Is Nothing And Not yourotherclass.flag Is lastline Then
lastline = CStr(yourotherclass.flag)
UpdateListBox(console, CStr(yourotherclass.flag))
End IfAlright 2 more things now.
We basically want this sub to loop, so the lazy way to do so is call the sub in form paint event.
So now in your other thread in the other class, simply put
Code
flag = "item to add"That should give you a basic idea of how this would work. This code is probably buggy, but I hope it helps some of you :)



