Results 1 to 6 of 6

Thread: Datagridview limit entries

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Datagridview limit entries

    How can i limit the user to enter only certain data in a datagrid. Lets say 0 - 9 only. When the user try's to enter any other char, it should stay 0

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Re: Datagridview limit entries

    THis is the code i got so far:

    Code:
     Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
            If e.FormattedValue IsNot Nothing AndAlso String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
                DataGridView1.Rows(e.RowIndex).ErrorText = "Absent Reason must not be empty"
                e.Cancel = True
                'DataGridView1.CurrentCell.value = 0 ----> THIS DOES NOT WORK !!!
            End If
        End Sub
    BUT!!.. how do i fill the empty cell with a value of 0. As you can see the line i used does not work!!

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Datagridview limit entries

    I wish people stopped using 'does not work' phrase and supplied real error mesages instead.



    P.S.
    You don't need to change the value, by the way. The validation procedure won't allow user to leave this cell until he supplies the correct value.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Re: Datagridview limit entries

    And I wish 'PEOPLE' would understand that when 'It does not Work', it means

    ....IT DOES NOT DO WHAT IT WANT!!

    That does not mean that a Error is generated, or even that the program stops...!!!

    I want it to replace an empty space or any other character that is NOT 0-9 with a 0.

    Does that help:

  6. #6
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Datagridview limit entries

    Not particularly.
    I tried it and it worked for me.

    Just out of curiosity - in your code above this line is commented. Are you sure you got it uncommented?

    Try this:

    Code:
    DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex ).Value = 0

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