user1247139
user1247139

Reputation:

Form1 controls and threading

Right now, the line of code I'm worrying about looks like this:

listView1.Items.Add(additional + message, icon);

Works fine, but only in Form1 of course. What do I need to do if I want to use the Add() method of my Listview from another class? (Multithreading 'n stuff.)

Upvotes: 0

Views: 69

Answers (2)

alexm
alexm

Reputation: 6882

Add a method on your form:

    public void AddMessageAsync(string message, int icon)
    {
        Action<string, int> handler = (aMessage, imageIndex) =>
            listView1.Items.Add("someMessage" + aMessage, imageIndex);


        BeginInvoke(handler, message, icon);
    }

Upvotes: 1

Justin Pihony
Justin Pihony

Reputation: 67075

Accessing the listview's items from another class is not multi-threading (which would cause other problems on the UI anyway). So, if you want to access the listView1 from another class, then you need to make the listview object public, and you will also need a reference inside of the class you are trying to access it from

Upvotes: 0

Related Questions