Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

Get Text from ListView Control - Managed C++ NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pantokrator - 14 Jun 2007 13:06 GMT
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
Ben Voigt [C++ MVP] - 14 Jun 2007 14:43 GMT
> Hi,
> I've searched the web and MSDN but couldn't find adequate information
[quoted text clipped - 25 lines]
> 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
Pantokrator - 14 Jun 2007 16:12 GMT
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
Ben Voigt [C++ MVP] - 15 Jun 2007 01:29 GMT
> 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.
[quoted text clipped - 10 lines]
>
> 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
Pantokrator - 15 Jun 2007 12:20 GMT
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
Massimo - 15 Jun 2007 12:54 GMT
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
Pantokrator - 15 Jun 2007 17:31 GMT
Thanks!
At last it worked!
Ben Voigt [C++ MVP] - 15 Jun 2007 18:32 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.