Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need Syntax help with a delegate for a listview

Posted on 2008-10-08
6
Medium Priority
?
541 Views
Last Modified: 2012-08-14
Friends,

I am getting the dreaded cross-threaded operation not allowed exception when I am trying to add items to my listview.  So, the simplest solution is to use a delegate.  Now, attached, you will my delegate code, except that I am having a problem with it.

If you look in here:

Me.BeginInvoke(ssd, New Object() {listViewToUpdate, ItemToAdd})

            Else
                Select Case listViewToUpdate
                    Case listViewToUpdate.lvShortCuts <-- Here I have the error:
'lvShortCuts' is not a member of 'System.Windows.Forms.ListView'. However, lvShortCuts is infact my listview.  Any idea what's wrong and how to fix it?

Thanks in advance!

Best Regards,
Eric
Private Delegate Sub AddListViewDelegate(ByVal listViewToUpdate As ListView, ByVal ItemToAdd As ListViewItem)
    Public Sub AddListViewItem(ByVal listViewToUpdate As ListView, ByVal ItemToAdd As ListViewItem)
        Try
 
 
            If Me.InvokeRequired Then
                Trace.WriteLine("UpdateScreenLabel - Invoke is required")
                Dim ssd As New AddListViewDelegate(AddressOf AddListViewItem)
 
                Me.BeginInvoke(ssd, New Object() {listViewToUpdate, ItemToAdd})
 
            Else
                Select Case listViewToUpdate
                    Case listViewToUpdate.lvShortCuts
                        lvShortCuts.Items.Add(ItemToAdd)
                End Select
            End If
 
        Catch ex As Exception
 
        End Try
 
    End Sub
 
    Enum listViewToUpdate
        lvShortCuts
    End Enum

Open in new window

0
Comment
Question by:indy500fan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22668602
try adding this:

Control.CheckForIllegalCrossThreadCalls = False
0
 

Author Comment

by:indy500fan
ID: 22668927
SameerJagdale,

I would rather not.  I am wanting to work on my Delagate and fix the syntax therein.

Best Regards,
Eric
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22669021
good luck :-)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22669034
BTW, what is this
Case listViewToUpdate.lvShortCuts
your listview is listViewToUpdate. right?
0
 

Author Comment

by:indy500fan
ID: 22669057
Well, the acutal name of the listview that I want to update is lvShortcuts, listViewToUpdate is where lvShortCuts is enumerated.
0
 

Accepted Solution

by:
indy500fan earned 0 total points
ID: 22669217
I got it.  Thanks anyway.

Here was the code I used to make it work:
    Private Delegate Sub AddListViewDelegate(ByVal listView As listViewToUpdate, ByVal ItemToAdd As String, ByVal SubItem1 As String, ByVal SubItem2 As String)
    Public Sub AddListViewItem(ByVal listView As listViewToUpdate, ByVal ItemToAdd As String, ByVal SubItem1 As String, ByVal SubItem2 As String)
        Try
 
            If Me.InvokeRequired Then
                Trace.WriteLine("UpdateScreenLabel - Invoke is required")
                Dim ssd As New AddListViewDelegate(AddressOf AddListViewItem)
 
                Me.BeginInvoke(ssd, New Object() {listView, ItemToAdd, SubItem1, SubItem2})
 
            Else
                Select Case listView
                    Case listViewToUpdate.lvShortCuts
                        Dim li As New ListViewItem
                        li = lvShortCuts.Items.Add(ItemToAdd)
                        li.SubItems.Add(SubItem1)
                        li.SubItems.Add(SubItem2)
                End Select
            End If
 
        Catch ex As Exception
 
        End Try
 
    End Sub
 
    Enum listViewToUpdate
        lvShortCuts
    End Enum

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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