title: CATIA C# Selection Search
body: <p>I'd like to search through the tree in CATIA, and return the names of the parts in the tree using C#. My current code is as follows: </p>
  
  <pre><code>    private void Search(object sender, EventArgs e)
      {
          string searchName = OriginalBox.Text;
          string name;
          INFITF.SelectedElement part;
  
          //CATIA.StartCommand("Search");
          try
          {
              Sel.Search("Name=" + searchName + "*, all");
  
              for (int i = 1; i &lt;= Sel.Count; i++)
              {
                  part = Sel.Item(i);
                  name = part.get_Name();
  
                  MessageBox.Show(i.ToString() + " : " + name);
              }
          }
          catch (IOException ex)
          {
              if (ex.Source != null)
                  MessageBox.Show(ex.Source);
              throw;
  
          }
      }
  </code></pre>
  
  <p>The MessageBox displays "CATIASelectedElement45". I am receiving the message "ERROR HRESULT E_FAIL has been returned from a call to a COM component." when assigning the Sel.Item(i) to part. </p>
  
  <p>How can I access the part name using Selection.Search?</p>