locked
Managing DataGridView New Record RRS feed

  • Question

  • hello

    DGV.DataSource = BindingSource

    I populated my data table as above code to DGV with "Allowed Add" property. but I can not manage "New Record". I want to force user to enter data in mandatory cell when this record must be added to me "BindingSource" and when user press ESC key on keyboard, my DGV ignore mandatory cell and delete "New Record".

    for the mandatory cell I put my code in "RowValidating" event but ESC dose not work.

    what shall I do?

    thank you all in advance

    Thursday, May 3, 2018 3:38 PM

All replies

  • Try setting required fields with AllowDBNull = False

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, May 3, 2018 3:57 PM
  • hello

    DGV.DataSource = BindingSource

    I populated my data table as above code to DGV with "Allowed Add" property. but I can not manage "New Record". I want to force user to enter data in mandatory cell when this record must be added to me "BindingSource" and when user press ESC key on keyboard, my DGV ignore mandatory cell and delete "New Record".

    for the mandatory cell I put my code in "RowValidating" event but ESC dose not work.

    what shall I do?

    thank you all in advance

    Hi mmbguide,

    If you want to cancel the current row data in datagridview when user press ESC, you can do something in DatagIrview_KeyDown

     Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
            If e.KeyCode = Keys.Escape Then
                DataGridView1.CurrentRow.Cells("Id").Value = 0
                DataGridView1.CurrentRow.Cells("Studentname").Value = ""
                DataGridView1.CurrentRow.Cells("Studentage").Value = 0
                bindsource.CancelEdit()
            End If
        End Sub

    But you said, for the mandatory cell I put my code in "RowValidating" event but ESC dose not work, I am not clear, can you describe more detailed info or post some code here?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 4, 2018 6:02 AM