CancelEdit does not keep focus on edited cell in DataGridView c#

Shaivya Sharma

When I enter some value in a cell in DataGridView and click on another cell the cellvalidating event handler code is executed. Even if validation fills, the cell on which I click gets highlighted. My requirement is that the cell should remain selected and cursor should blink in the cell for editing after removing the invalid value. Am using the below code if the validation fails:

DataGridView1.CancelEdit();

I have tried adding

DataGridView1.CurrentCell.Selected = true;
DataGridView1.BeginEdit(true);
user3093781

You need to use e.Cancel = true like below.

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    int i;

    if (!int.TryParse(e.FormattedValue.ToString(), out i))
    {
        e.Cancel = true;
        MessageBox.Show("Please input a integral number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change of the edited cell in a datagridview cell

From Dev

focus in a cell value of DataGridView C# windows forms on adding a row

From Dev

c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus

From Dev

c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus

From Dev

Button Click not firing When focus is set to next cell in DataGridView on CellEndEdit

From Dev

Set the Focus on a particular DataGridView Cell when the Form loads

From Dev

save edited DataGridView to Datatable

From Dev

Restoring Previous cell value in c# datagridview

From Dev

Make one cell editable in datagridview c#

From Dev

C# retrieve cell value from datagridview

From Dev

DataGridView filter hiding edited items

From Dev

How can I compare datagridview cell of datagridview1 with another datagridview cell of datagridview2 in C#

From Dev

DataGridView not losing focus

From Dev

MFC VC++: How to keep focus mark or selection mark when CListCtrl does not have focus

From Dev

MFC VC++: How to keep focus mark or selection mark when CListCtrl does not have focus

From Dev

C# How to Highlight Current DataGridVeiw Cell in Focus

From Dev

C# keep row selection after dataGridView refresh

From Dev

Loading cell values in dataGridView from text file C#

From Dev

How to disable per cell tab stop of DataGridView in C#?

From Dev

how to add text to a dataGridView cell in different form c#

From Dev

Entity Framework, Multiple values 1 cell/ Datagridview c#

From Dev

Getting the location of cell when clicked in DataGridView C# windows form

From Dev

Selecting a cell at the time of Selecting a row in DataGridView C#

From Dev

C# DataGridView: How to change a single cell value

From Dev

KeyUp event fire for only specific cell in datagridview c#

From Dev

Change datagridview cell to combobox if empty/(null) c#

From Dev

Winform C# Update DataGridView on DataTable Cell value changed

From Dev

Highlight the particular text inside a datagridview cell in c#windows application

From Dev

c# winform datagridview cell click to TabControl Page

Related Related

  1. 1

    Change of the edited cell in a datagridview cell

  2. 2

    focus in a cell value of DataGridView C# windows forms on adding a row

  3. 3

    c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus

  4. 4

    c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus

  5. 5

    Button Click not firing When focus is set to next cell in DataGridView on CellEndEdit

  6. 6

    Set the Focus on a particular DataGridView Cell when the Form loads

  7. 7

    save edited DataGridView to Datatable

  8. 8

    Restoring Previous cell value in c# datagridview

  9. 9

    Make one cell editable in datagridview c#

  10. 10

    C# retrieve cell value from datagridview

  11. 11

    DataGridView filter hiding edited items

  12. 12

    How can I compare datagridview cell of datagridview1 with another datagridview cell of datagridview2 in C#

  13. 13

    DataGridView not losing focus

  14. 14

    MFC VC++: How to keep focus mark or selection mark when CListCtrl does not have focus

  15. 15

    MFC VC++: How to keep focus mark or selection mark when CListCtrl does not have focus

  16. 16

    C# How to Highlight Current DataGridVeiw Cell in Focus

  17. 17

    C# keep row selection after dataGridView refresh

  18. 18

    Loading cell values in dataGridView from text file C#

  19. 19

    How to disable per cell tab stop of DataGridView in C#?

  20. 20

    how to add text to a dataGridView cell in different form c#

  21. 21

    Entity Framework, Multiple values 1 cell/ Datagridview c#

  22. 22

    Getting the location of cell when clicked in DataGridView C# windows form

  23. 23

    Selecting a cell at the time of Selecting a row in DataGridView C#

  24. 24

    C# DataGridView: How to change a single cell value

  25. 25

    KeyUp event fire for only specific cell in datagridview c#

  26. 26

    Change datagridview cell to combobox if empty/(null) c#

  27. 27

    Winform C# Update DataGridView on DataTable Cell value changed

  28. 28

    Highlight the particular text inside a datagridview cell in c#windows application

  29. 29

    c# winform datagridview cell click to TabControl Page

HotTag

Archive