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

Get Text from ListView Control - Managed C++ NET

Hi,
I've searched the web and MSDN but couldn't find adequate information
on retrieving the text of a subitem of a listviewitem.

What I want to do is simple. I have a listview control with 2 columns
and a large number of listviewitems.
Every time I click on a row (one of the listviewitems), I would like
to get the String* representation of the second column cell.

First I get the index as follows:

int ind=0;

for (int j=0; j<listView1->Items->Count; j++)
{
if (listView1->Items->Item[j]->Selected)
ind = listView1->Items->Item[j]->Index;

}

Then, I get my listviewitem pointer as follows:
ListViewItem* item = listView1->Items->Item[ind];

if I write:
item->Text;
it will return me the string of the first column

What do I do after that in order to get the String* type of the second
subitem??

Many thanks in advance

Jun 14 '07 #1
7 7326

"Pantokrator" <ad****@shotoku.co.ukwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
Hi,
I've searched the web and MSDN but couldn't find adequate information
on retrieving the text of a subitem of a listviewitem.

What I want to do is simple. I have a listview control with 2 columns
and a large number of listviewitems.
Every time I click on a row (one of the listviewitems), I would like
to get the String* representation of the second column cell.

First I get the index as follows:

int ind=0;

for (int j=0; j<listView1->Items->Count; j++)
{
if (listView1->Items->Item[j]->Selected)
ind = listView1->Items->Item[j]->Index;

}

Then, I get my listviewitem pointer as follows:
ListViewItem* item = listView1->Items->Item[ind];

if I write:
item->Text;
it will return me the string of the first column

What do I do after that in order to get the String* type of the second
subitem??
Did you look at the SubItems property?

Anyway, you should upgrade to C++/CLI as soon as possible. Managed
Extensions for C++ is buggy and abandoned by Microsoft.
>
Many thanks in advance

Jun 14 '07 #2
Hi Ben, you are right...I've spent enormous time just for one control
and all i want to do is something easy.
But I'm stuck you see, because I've written a lot of code and if I
change back to MFC it will take me time to re-write everything.
I've looked at the SubItems property but there isn't anything 'sound'
to say how to get the test from a subitem.
OK. you can easily add a subitem like item1->SubItems->Add(S"1"); but
how do you get that subitem back in a string....I don't understand...
This is from MSDN:

Property Value
A ListViewItem.ListViewSubItemCollection that contains the subitems.

Remarks
Using the ListViewItem.ListViewSubItemCollection, you can add
subitems, remove subitems, and obtain a count of subitems....

Doesn't say anything on How to retrieve the text...

Any more thoughts?
Thanks again

Jun 14 '07 #3

"Pantokrator" <ad****@shotoku.co.ukwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
Hi Ben, you are right...I've spent enormous time just for one control
and all i want to do is something easy.
But I'm stuck you see, because I've written a lot of code and if I
change back to MFC it will take me time to re-write everything.
Wasn't suggesting going back to MFC. Was recommending you use the new
managed C++, C++/CLI, which comes with Visual Studio 2005, and totally
replaces "Managed Extensions for C++".
I've looked at the SubItems property but there isn't anything 'sound'
to say how to get the test from a subitem.
OK. you can easily add a subitem like item1->SubItems->Add(S"1"); but
how do you get that subitem back in a string....I don't understand...
This is from MSDN:

Property Value
A ListViewItem.ListViewSubItemCollection that contains the subitems.

Remarks
Using the ListViewItem.ListViewSubItemCollection, you can add
subitems, remove subitems, and obtain a count of subitems....

Doesn't say anything on How to retrieve the text...
It's a collection, you can get the members just like you did with Items.
Each member is a ListViewSubItem, with ForeColor, Font, Text properties...
>
Any more thoughts?
Thanks again

Jun 15 '07 #4
Thanks Ben, but unfortunately my company doesn't want to pay for any
vs 2005 upgrade and I desperately need to solve this problem.
Have you got any example to retrieve the text from the collection
ListViewSubItem?? I'm stuck unfortuantely

Thanks for your help

Jun 15 '07 #5
I dont't know if I can help you but in the past I worked with C++ .NET
2003 and I read text from subitems in this way:

String *s = listview->Items->get_Item(0)->SubItems->get_Item(0)->Text;

Bye
Massimo
Pantokrator ha scritto:
Thanks Ben, but unfortunately my company doesn't want to pay for any
vs 2005 upgrade and I desperately need to solve this problem.
Have you got any example to retrieve the text from the collection
ListViewSubItem?? I'm stuck unfortuantely

Thanks for your help
Jun 15 '07 #6
Thanks!
At last it worked!

Jun 15 '07 #7

"Pantokrator" <ad****@shotoku.co.ukwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
Thanks Ben, but unfortunately my company doesn't want to pay for any
vs 2005 upgrade and I desperately need to solve this problem.
Have you got any example to retrieve the text from the collection
ListViewSubItem?? I'm stuck unfortuantely
using VC++ 2005 Express is preferable to VS 2003 Managed Extensions for C++
because a lot of runtime bugs were fixed.
>
Thanks for your help
Jun 15 '07 #8

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

Similar topics

1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
4
by: VM | last post by:
Can I add text of different colors to a listview? Let's say I want to add, on one line, the text "This is my message" on my listview. Would it be possible to add this sentence to the listview...
3
by: Steve | last post by:
I have windows form with ListView control. The ListView control has few columns which user can sort by clicking the column header. I want the column header have the small triangle indicator of...
6
by: ReMEn | last post by:
I was wondering how I can use a listview effectively in managed c++ ..net. Basically I'm trying to get the index of the selected item in the list view, then get the "tag" attribute of that item to...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
0
by: Lucky | last post by:
hi guys, i'm looking for a soultion that helps me to show the subitem text of the listview control in the tooltip when the mouse pointer hovers on the subitem. i've found on solution, according to...
0
by: sonu | last post by:
Hi all, I have a listview control which has four columns like { Col1, Col2, Col3, Col4}. I add data in listview like this, dim lvitem as listviewItem
3
by: Hrvoje Voda | last post by:
How to add a list of images into listview? Should I use different tool? Hrcko
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.