473,659 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListViewItem question

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.

The user selects a ticket type from a drop down, and enters a ticket
number in a text box, then clicks 'add'. This adds those strings to
the first two columns of the ListView, and I want to be able to fill in
the rest of the columns of that 'row' programmaticall y based on data
from a database.

How do I access each element in the 'rows'? I use "rows" because I
don't know of a more correct term.

All I've gotten so far is this:

foreach (ListViewItem lvi in lvRecords.Items ) {
}

I've tried accessing lvi.SubItems but I'm not at all sure how to make
it work.

Can anyone share information on how to access individual cells in the
ListView programmaticall y?

Nov 17 '05 #1
2 1443
Here is a code snippet I had handy that illustrates getting at the subItems
of each ListViewItem:

private void btnDone_Click(o bject sender, EventArgs e)
{
if (this.listView1 .Items.Count == 0)
{
this.Close();
return;
}
ListViewItem myItem = null;
int checkedItems = 0;
//string sipUserId = String.Empty;
foreach (ListViewItem itm in this.listView1. Items)
{
if (itm.Checked)
{
myItem = itm;
checkedItems++;

}
}
if (checkedItems > 1)
{
this.lblMessage .Text = "Check 1 Item only.";
return;
}
else if (checkedItems == 1)
{
// myItem.SubItems[1].Text+" "
this.chosenSipU serId = myItem.SubItems[0].Text +"|"
+myItem.SubItem s[2].Text;
this.OnNotifyCa ller();
this.Close();
}

} // end btnDone_Click
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"na*******@gmai l.com" wrote:
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.

The user selects a ticket type from a drop down, and enters a ticket
number in a text box, then clicks 'add'. This adds those strings to
the first two columns of the ListView, and I want to be able to fill in
the rest of the columns of that 'row' programmaticall y based on data
from a database.

How do I access each element in the 'rows'? I use "rows" because I
don't know of a more correct term.

All I've gotten so far is this:

foreach (ListViewItem lvi in lvRecords.Items ) {
}

I've tried accessing lvi.SubItems but I'm not at all sure how to make
it work.

Can anyone share information on how to access individual cells in the
ListView programmaticall y?

Nov 17 '05 #2
that solution is so simple I've glossed over it at least 20 times
trying to figure it out.

For those of you that don't see it: SubItems[int].Text

Thank You Very Much, Peter.

Nov 17 '05 #3

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

Similar topics

0
1911
by: afatdog | last post by:
I want to change the ListViewItem's StateImageIndex to change. private void Button_xx_Click(object sender, System.EventArgs e) { ListViewItem.StateImageIndex++; } But the ListViewItem's StateImageIndex does not clear the original image, and the ListView' ListViewItem show two
2
1627
by: Max Adams | last post by:
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"} );
6
13092
by: grs | last post by:
The following is a code example from the Microsoft MSDN. My question is on the following three lines of code: ListViewItem item1 = new ListViewItem("item1",0); ListViewItem item2 = new ListViewItem("item2",1); ListViewItem item3 = new ListViewItem("item3",0); You would in most cases know the ListViewItem name or the number of items to create (item1,item2 etc). How would you create this individual rows programmatically ?
10
3514
by: Gav | last post by:
I am trying to have a ListView to dispay a list of names and want to have an id stored within the list but not visable. I have tried to go about doing this by using the ListViewItem and setting the Text and Tag properties. Problem is when I add the ListViewItem to the ListView I get the following ListViewItem: {Test1} ListViewItem: {Test2} ListViewItem: {Test3}
0
8428
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
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
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...
1
6179
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
5649
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
2752
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
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.