Code for setFocusToErrorOnRow

I just received an anonymous comment to the Blogger version of the Data validation in .Net using ErrorProvider and DataSet errors post, asking for the code to setFocusToErrorOnRow. This method is designed for a ComponentOne TrueDBGrid - my code is in a descendant of the C1TrueDBGrid class and wouldn't apply to a .Net data grid. Even so, here is the code - perhaps it will be useful, and as always, suggestions are welcome!

private bool setFocusToErrorOnRow (DataRow row, int rowIndex)

{

  bool errorProcessed = false;

  if (row.HasErrors)

  {

    DataColumn[] columnsInError = row.GetColumnsInError();

    if (columnsInError.Length > 0)

    {

      int columnIndex = 0;

      // Attempt to locate column in error on grid, so that we can set focus there

      foreach (C1.Win.C1TrueDBGrid.C1DisplayColumn displayColumn in this.Splits[0].DisplayColumns)

      {

        if (displayColumn.DataColumn.DataField == columnsInError[0].ColumnName)

        {

          this.Row = rowIndex;

          this.Col = columnIndex;

          errorProcessed = true;

          break;

        }

        columnIndex++;

      }

 

      // If we couldn't find a column, at least set focus to the row

      if (!errorProcessed)

      {

        this.Row = rowIndex;

        errorProcessed = true;

      }

    }

    else

    {

      this.Row = rowIndex;

      errorProcessed = true;

    }

  }

  return errorProcessed;

}

Published Wed, Jul 20 2005 8:17 PM by Joshua Langemann

Comments

Wednesday, July 20, 2005 10:40 PM by Jan Schreuder

# re: Code for setFocusToErrorOnRow

I've posted code to do this in a .Net DataGrid some time ago. Here's the link: http://bloggingabout.net/blogs/jschreuder/archive/2004/10/07/1458.aspx
Wednesday, July 20, 2005 10:42 PM by Jan Schreuder

# re: Code for setFocusToErrorOnRow

Not entirely the same of course, my code merely set's the row to the desired row in you grid ;-)

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 6 and 7 and type the answer here: