954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SelectedIndices for listView

I wonder how it is possilbe to access the first listitem in the listView.
I know that each item has an index like the listBox Control and that you could access them with the member ->SelectedIndices but when writing the code below, the compiler says:

'==' : no conversion from 'int' to 'System::Windows::Forms::ListView:: SelectedIndexCollection ^

if( listView2->SelectedIndices == 0 )
{
}
Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

>>listView2->SelectedIndices
SelectedIndices is not an integer -- its an array of integers. listBox1->SelectedIndices->Count is probably what you want.

Did you see the example c++ Microsoft code here

Read the comments carefully.

private:
   void FindAllOfMyString( String^ searchString )
   {
      // Set the SelectionMode property of the ListBox to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Set our intial index variable to -1.
      int x = -1;

      // If the search string is empty exit.
      if ( searchString->Length != 0 )
      {
         // Loop through and find each item that matches the search string.
         do
         {

            // Retrieve the item based on the previous index found. Starts with -1 which searches start. 
            x = listBox1->FindString( searchString, x );

            // If no item is found that matches exit.
            if ( x != -1 )
            {
               // Since the FindString loops infinitely, determine if we found first item again and exit.
               if ( listBox1->SelectedIndices->Count > 0 )
               {
                  if ( x == listBox1->SelectedIndices[ 0 ] )
                                    return;
               }

               // Select the item in the ListBox once it is found.
               listBox1->SetSelected( x, true );
            }
         }
         while ( x != -1 );
      }
   }
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I red the example and I red this link and also found out that listView1->SelectedIndicies->Count could be used but I wrote the first Item as 0 as I thought it was zerobased but the first Item for Count is == 1 so that works fine. Thanks for help !

listBox1->SelectedIndices->Count == 1

>>listView2->SelectedIndices SelectedIndices is not an integer -- its an array of integers. listBox1->SelectedIndices->Count is probably what you want.

Did you see the example c++ Microsoft code here

Read the comments carefully.

private:
   void FindAllOfMyString( String^ searchString )
   {
      // Set the SelectionMode property of the ListBox to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Set our intial index variable to -1.
      int x = -1;

      // If the search string is empty exit.
      if ( searchString->Length != 0 )
      {
         // Loop through and find each item that matches the search string.
         do
         {

            // Retrieve the item based on the previous index found. Starts with -1 which searches start. 
            x = listBox1->FindString( searchString, x );

            // If no item is found that matches exit.
            if ( x != -1 )
            {
               // Since the FindString loops infinitely, determine if we found first item again and exit.
               if ( listBox1->SelectedIndices->Count > 0 )
               {
                  if ( x == listBox1->SelectedIndices[ 0 ] )
                                    return;
               }

               // Select the item in the ListBox once it is found.
               listBox1->SetSelected( x, true );
            }
         }
         while ( x != -1 );
      }
   }
Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You