Check chronological order and return the out of order row
<p>This is a small logic question. My datagrid has date time values  in chronological order. 
If the user enters an out-of-order date time, the program should highlight the row which is out-of-order. 
For eg: This is the initial order. </p>

<pre><code>10/5/2010 11:59:59  
10/6/2010 00:00:00  
10/6/2010 11:59:59
</code></pre>

<p>Suppose the user enters</p>

<pre><code>   10/5/2010 11:59:59   
    ***10/7/2010 00:00:00***    
    10/6/2010 11:59:59  
    10/7/2010 00:00:00 
</code></pre>

<p>here <code>10/7/2010 00:00:00</code> is the out of order and the program behaves correctly. </p>

<p>Suppose the user enters </p>

<pre><code>10/5/2010 11:59:59
10/6/2010 00:00:00
***10/5/2010 11:59:59***
10/7/2010 00:00:00
</code></pre>

<p>Here <code>10/5/2010 11:59:59</code> is the out or order row. But the program highlights <code>10/6/2010 00:00:00</code>. </p>

<p>Here's my code to check the above:</p>

<pre><code>for (int nRow = 1; nRow &lt; pSeries.Count; ++nRow)
{
    // validation1
   if (!check_range(nRow, i, pSeries[nRow].tim))
   {
       row = nRow;
       err = (short)err_typ.e_out_range;
       goto err_exit;
   }
}

public bool check_range(int np, int nCol, DateTime dt)
{
    DataArray pdata = GetDataArray(nCol);

    bool valid = (np &lt;= 0 || pdata[np - 1].Datetim &lt;= dt) &amp;&amp;
         (np &gt;= (pdata.Count - 1) || dt &lt;= pdata[np + 1].Datetim );
    return valid;
}
</code></pre>

<p><code>DataArray</code> is a user defined array of datetime values. <code>pSeries</code>,<code>pData</code> are of type <code>DataArray</code>.
So when I say <code>pdata[np - 1].DateTime</code> it refers to the datetime cell. </p>
