Results 1 to 2 of 2

Thread: Datagridview _CellValidating question

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    34

    Datagridview _CellValidating question

    I have a datagridview and in the _CellValidating event I am checking a cell to make sure it is filled in. If it is not, I want to stop editing, display a msgbox, and highlight the particular cell. Here is my code :
    Code:
     
    If e.ColumnIndex = 2 Then
        If e.FormattedValue = "" Then
            If Me.dgvFish.IsCurrentCellDirty Then
                MsgBox("Sample Number is a required field.")
                Me.dgvFish.EndEdit()
                e.Cancel = True
                Me.dgvFish.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.Aquamarine
            End If
        End If
    End If
    For some reason, I can't get the cell's backcolor to be filled in. Any suggestions ? Thanks.
    Last edited by bfoley; Mar 11th, 2010 at 03:42 PM.

  2. #2
    Lively Member eatmycode's Avatar
    Join Date
    Mar 2010
    Location
    Kingston upon Hull
    Posts
    74

    Re: Datagridview _CellValidating question

    Try replacing 2 with e.ColumnIndex
    Technik ... Kniff, die Welt so einzurichten, dass wir sie nicht erleben mussen

    Max Frisch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width