Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Max Adams
Guest
 
Posts: n/a
#1: Nov 16 '05
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



Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Nov 16 '05

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


Max Adams <rubberducky703@hotmail.com> wrote:[color=blue]
> 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[/color]

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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Max Adams
Guest
 
Posts: n/a
#3: Nov 16 '05

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


Sorted it.

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


[color=blue]
> 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[/color]
I[color=blue]
> 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.[/color]


Closed Thread