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 )
{
}

>>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 );
      }
   }

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 );
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.