All pastes #27090 Raw Edit

Mine

public text v1 · immutable
#27090 ·published 2005-10-30 22:25 UTC
rendered paste body
        //-- function used to reselect the row based on column value
        private void ReSelectRow(DataGridView myDataGrid, int iColIndex, string sColValue)
        {
            /* check to make sure we have a value */
            if (myDataGrid != null && sColValue.Length > 0)
            {
                int iRow;
                DataSet myDS = (DataSet)myDataGrid.DataSource;

                /* loop through the collection and check the value */
                for (iRow = 0; iRow < myDS.Tables[0].Rows.Count; iRow++)
                {
                    string myValue = myDataGrid[iColIndex, iRow].Value.ToString();

                    if (myValue == sColValue)
                    {
                        myDataGrid.Rows[iRow].Selected = true;
                        myDataGrid.Rows[iRow].Cells[iColIndex].Selected = true;
                        break;
                    }
                }
            }
        }