By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,068 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,068 IT Pros & Developers. It's quick & easy.

How to retrieve listview subitem data in C#.net 2008?

100+
P: 126
Hello Friends,

I am using C#NET2008, Window Application with LISTVIEW.
I encounter an interesting problem while trying to retrieve 2 ListView SubItem column data of ORDERDATE and INVOICE for filling the TEXTBOX Control.

This is the ListView data display
CustID OrderDate Invoice
54321 25/12/2010 45363
56441 16/12/2010 45362

-----------------------------------------
After retrieving the SubItem Data into the TextBox instead of of just the OrderDate and Invoice data. This is what appeared on the TextBox:

ListView1SubItem: {25/12/2010}
ListView1SubItem: {45363}

Here are the coding that caused the above result.
Expand|Select|Wrap|Line Numbers
  1. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  2.   {           
  3.   txtOrderDate.Text = Convert.ToString(this.listView1.SelectedItems[0].SubItems[1]);
  4.  txtInvoice.Text = Convert.ToString(this.listView1.SelectedItems[0].SubItems[2]);        
  5.   }
Feb 25 '11 #1
Share this Question
Share on Google+
2 Replies


bentleyw
P: 32
What it's doing now is showing you the string representation of the referenced ListView SubItem object. What I believe you want is the "Text" property value associated with the SubItem, like below:

Expand|Select|Wrap|Line Numbers
  1. txtOrderDate.Text = listView1.SelectedItems[0].SubItems[1].Text;
  2. txtInvoice.Text = listView1.SelectedItems[0].SubItems[2].Text; 
Feb 27 '11 #2

100+
P: 126
Hello friends, finally I got the coding working by using this

Expand|Select|Wrap|Line Numbers
  1. strOrderID =  this.listView1.SelectedItems[0].Text ;
  2.  
  3. strOrderDate =  this.listView1.SelectedItems[0].SubItems[1].Text;
  4.  
  5. strProdID = this.listView1.SelectedItems[0].SubItems[2].Text;
Feb 27 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.