Solved

VB.NET Listbox InvokeRequierd

Posted on 2013-01-07
4
439 Views
Last Modified: 2013-01-20
Hi, I have a problem..
this code works..
 Private Delegate Sub SetTextBoxTextInvoker(ByVal text As String)

  Private Sub SetTextBoxCom01(ByVal text As String)
        'If Me.uxCom1txt.InvokeRequired Then
        '    Me.uxCom1txt.Invoke(New SetTextBoxTextInvoker(AddressOf SetTextBoxCom01), text)
        'Else
        '    Me.uxCom1txt.ADD(text)
        'End If

Open in new window


But I need to change to an listbox..
Can´t figure out how to get it to work..

        If LISTBOX1.add.InvokeRequired Then
            Me.LISTBOX1.Invoke(New SetTextBoxTextInvoker(AddressOf SetTextBoxCom01), text)
        Else
            Me.LISTBOX1.Text = text
        End If

Open in new window



VB.NET Visual studio 2010
0
Comment
Question by:kavvis
  • 2
4 Comments
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 38751217
A ListBox doesn't have a Text property. Are you sure you didn't intend to add the incoming parameter to the Items collection?

e.g.

        If LISTBOX1.add.InvokeRequired Then
            Me.LISTBOX1.Invoke(New SetTextBoxTextInvoker(AddressOf SetTextBoxCom01), text)
        Else
            Me.LISTBOX1.Items.Add(text)
        End If

Open in new window

0
 

Author Comment

by:kavvis
ID: 38751634
Hi I just tried to show an exampel.. I rally don"t know The syntax... :) that"s why I need help
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 38751906
You can do:
    Private Sub AddToListBox(ByVal text As String)
        If ListBox1.InvokeRequired Then
            Me.ListBox1.Invoke(New Action(Of String)(AddressOf AddToListBox), New Object() {text})
        Else
            Me.ListBox1.Items.Add(text)
        End If
    End Sub

Open in new window

0
 

Author Closing Comment

by:kavvis
ID: 38798206
It´s seems to work.. But somehow I get problem when I trie to use the data later on.. but I have to se it..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now