Question about using delegates with a string paramater to return a ListViewItem object...

M

Max Adams

Question about using delegates with a string paramater to return a
ListViewItem object...

All,

I have a thread and I want this thread to post messages to the main GUI
thread using a delegate. This is my code fragment:

ListViewItem lview = m_form.Invoke( m_form.m_DelegateAddItem, new object[]
{"hello"} );

This does not compile; m_form is a reference to my main form,
m_DelegateAddItem is obviously my delegate.

I have two questions, how can I pass a string to this delegate and how can I
get the return value back from this delegate?

My delegate is definied as such:
(AddItem is my function for m_DelegateAddItem)

private ListViewItem AddItem( string str )
{
return m_ctrlReq.Items.Add( str );
}

I want to use the listviewitem i get returned to append data to this
specific row in my list box.

Thanks
PT
 
J

Jon Skeet [C# MVP]

Max Adams said:
Question about using delegates with a string paramater to return a
ListViewItem object...

All,

I have a thread and I want this thread to post messages to the main GUI
thread using a delegate. This is my code fragment:

ListViewItem lview = m_form.Invoke( m_form.m_DelegateAddItem, new object[]
{"hello"} );

This does not compile

When saying that something doesn't compile, *always* say what the
compilation error is.

In this case, at a guess, just casting the return value of
m_form.Invoke to ListViewItem will solve things. If it doesn't,
could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
M

Max Adams

Sorted it.

m_lview = (ListViewItem)m_form.Invoke( m_form.m_DelegateAddItem, new
string[] { "A", "A", "A", "A", "A"} );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top