title: DevExpress XtraGrid : What is the proper way to obtain the RowHandle from an Object
body: <p>I am listing a collection of date ranges (each date range is represented by a <em>Period</em> object) in a DevExpress <strong>XtraGrid</strong> (WinForms).</p>
  
  <p>In a method which splits a Period in two (the split date is entered by the user), the code does this :</p>
  
  <ol>
  <li>Obtains a Period reference on the focused row. ((Period)GridViewPeriods.GetRow(selectedRows[0]);)</li>
  <li>Clones the selected period.</li>
  <li>Obtains a reference on the newly cloned Period.</li>
  </ol>
  
  <p>After the job is done, I want to put the focus on the newly cloned Period. At this point, I only have my two Period references.</p>
  
  <p>I haven't found any method in the XtraGrid that could locate a row based on it's value (like returning a RowHandle by passing an object).</p>
  
  <p>I ended up writing this helper method :</p>
  
  <pre><code>    public int GetDataRowIndex(RatePeriod period)
      {
          int foundIndex = 0;
  
          for (int i = 0; i &lt; GridViewRatePeriods.DataRowCount; i++)
          {
              if ((RatePeriod)GridViewRatePeriods.GetRow(i) == period)
              {
                  foundIndex = i;
                  break;
              }
          }
          return foundIndex;
      }
  </code></pre>
  
  <p>Then I set the focus on the newly created Period like this :</p>
  
  <pre><code>GridViewPeriods.FocusedRowHandle = GetDataRowIndex(tailingPeriod);
  </code></pre>
  
  <p>Is there any shorter or smarter way to do that ?</p>