473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Delega teAddItem, new object[]
{"hello"} );

This does not compile; m_form is a reference to my main form,
m_DelegateAddIt em 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_DelegateAddIt em)

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 1630
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_Delega teAddItem, 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.co m>
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_Delega teAddItem, 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_Delega teAddItem, new object[]
{"hello"} );

This does not compile; m_form is a reference to my main form,
m_DelegateAddIt em 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_DelegateAddIt em)

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
2532
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; using System.ComponentModel; using System.Windows.Forms; using System.Data;
1
5061
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 with the ADSI NT Provider and only supported in the LDAP Provider. So given an UserId (UID) how can I read the First Name and Last Name using LDAP Provider. If anybody can help me with a C# sample code it would of great help. Thanks in advance.
1
2839
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 remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because essentially my worker thread updates the UI, which is BAD. So, here I am trying to figure out how...
0
1643
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 throws error "-1 is not a valid index" when the sorting is done with listview. I have no problem using the same custom sorter for an arraylist of listviewitems. A bug in listview control? Any suggestion? Thanks, -sorpor
2
1445
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 number of 'rows' in the ListView, anywhere from 1 to 100 or even 1000. The purpose of the program is to allow a user to keep an eye on tickets in a ticketing database.
10
1804
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 referencing both: System.Drawing System.Drawing.Design
3
2316
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 arguments What to do? Please tell me concretely how to get rid of this error in terms of code. Many thanks,
6
1403
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, it's essentially a pointer to a piece of code somewhere else in memory. It therefore (to me anyway) makes sense to define delegates with their signatures and be able to use those signatures at different points in
4
237
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: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
8913
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.