473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Nov 16 '05 #1
2 1616
Max Adams <ru************@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Sorted it.

m_lview = (ListViewItem)m_form.Invoke( m_form.m_DelegateAddItem, new
string[] { "A", "A", "A", "A", "A"} );
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.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vanessa | last post by:
With this program I can do one selection, but upon the second I get an error where ///////////////// is indicated. Please help. using System; using System.Drawing; using System.Collections;...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
0
by: sorpor | last post by:
I am trying to create a custom listviewsorter by implementing IComparer. My listview has check boxes and the purpose is to move checked item to top of list. They all will be sorted ascendingly. It...
2
by: naikrovek | last post by:
Hello all. I have a ListView on a form, that has columns added at design-time but will be populated run-time. So, I know what the columns will be, and I know that I will have an arbitrary...
10
by: > Adrian | last post by:
I am getting these errors: DrawListViewItemEventArgs' could not be found DrawListViewSubItemEventArgs' could not be found DrawListViewColumnHeaderEventArgs' could not be found I am already...
3
by: > Adrian | last post by:
In VS 2003 I could sort a column in a list view using the code below, hover, in V2005 I get this error: Error 1 Using the generic type 'System.Collections.Generic.IComparer<T>' requires '1' type...
6
by: damiensawyer | last post by:
Hi, Can someone please explain to me something about delegates? My understanding is as follows. A delegate is basically an object that can hold a reference to a "method" somewhere. That is,...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.