473,382 Members | 1,359 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,382 software developers and data experts.

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' programmatically 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 programmatically?

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

private void btnDone_Click(object 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.chosenSipUserId = myItem.SubItems[0].Text +"|"
+myItem.SubItems[2].Text;
this.OnNotifyCaller();
this.Close();
}

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


"na*******@gmail.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' programmatically 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 programmatically?

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
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...
2
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....
6
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...
10
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.