473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Listview problem

Hi All, I'm having a problem retrieving subitems from a listview using the string indexer method, my code for filling the lv is as
shown below

// take it as read there is data in the dataset.
foreach (DataRow dr in this.dsArt39Benefics.Tables[0].Rows)
{
lvi = new ListViewItem(dr["BenName"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine1"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine2"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine3"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine4"].ToString());
lvi.SubItems.Add(dr["CreateDate"].ToString());
lvi.SubItems.Add(dr["CreateUser"].ToString());
lvi.SubItems.Add(dr["AmendDate"].ToString());
lvi.SubItems.Add(dr["AmendUser"].ToString());

this.lvBeneficialOwnersNameAddress.Items.Add(lvi);

}

Later in the code I try to retrieve a value like this

ListViewItem lvi = this.lvBeneficialOwnersNameAddress.SelectedItems[0];

string s = lvi.SubItems["AmendUser"].Text;
the string s is always null, however, if I do it this way (the code below) it works, anyone know why ?

ListViewItem lvi = this.lvBeneficialOwnersNameAddress.SelectedItems[0];

string s = lvi.SubItems[8].Text;
Jan 5 '07 #1
1 1068
I think you forgot to create the columns in the ListView :

lvi.Columns.Add("Ben_AddrLine1");
"Pete Kane" <pj**********@uku.co.ukwrote in message
news:u0**************@TK2MSFTNGP02.phx.gbl...
Hi All, I'm having a problem retrieving subitems from a listview using the
string indexer method, my code for filling the lv is as
shown below

// take it as read there is data in the dataset.
foreach (DataRow dr in this.dsArt39Benefics.Tables[0].Rows)
{
lvi = new ListViewItem(dr["BenName"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine1"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine2"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine3"].ToString());
lvi.SubItems.Add(dr["Ben_AddrLine4"].ToString());
lvi.SubItems.Add(dr["CreateDate"].ToString());
lvi.SubItems.Add(dr["CreateUser"].ToString());
lvi.SubItems.Add(dr["AmendDate"].ToString());
lvi.SubItems.Add(dr["AmendUser"].ToString());

this.lvBeneficialOwnersNameAddress.Items.Add(lvi);

}

Later in the code I try to retrieve a value like this

ListViewItem lvi = this.lvBeneficialOwnersNameAddress.SelectedItems[0];

string s = lvi.SubItems["AmendUser"].Text;
the string s is always null, however, if I do it this way (the code below)
it works, anyone know why ?
>
ListViewItem lvi = this.lvBeneficialOwnersNameAddress.SelectedItems[0];

string s = lvi.SubItems[8].Text;

Jan 5 '07 #2

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

Similar topics

0
by: Steph. | last post by:
I use a ListView in a form to display Data from an SQL db. My problem is that I can fill the listview in less than a second when I show the form AFTER filling the listview, but I take 35...
15
by: Wiktor Zychla | last post by:
today we've found a critical issue regarding the ListView from Windows.Forms. it was confirmed on several machines with Win2K and XP. here's the problem: create a ListView with about 50000 rows....
0
by: Sérgio Almeida | last post by:
Greetings I have a problem using listview control. Well, I belive that this is not realy a problem, but it's consuming me precious time. Here is the scenario (an example of my problem). I...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
4
by: firefox | last post by:
Hola Foro!, tengo una rutina que permite agregar varios elementos o items de una sola vez en un ListView. Lo que sucede es que en el momento que se añaden los items al ListView se pone todo blanco,...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
3
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
2
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I am attempting to insert a simple record with LinqDataSource from a ListView, however I always get a message saying "....LinqDataSource 'dataSource' has no values to insert. Check that the...
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...
0
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...
0
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...
0
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.