KeyUp event fire for only specific cell in datagridview c#

Sharanamma Jekeen

I think this is common issue but i am unable to find the solution so i am putting here,
I am working on windows application project, in that i need to get the employee details where i have restriction like salary column should be numeric so applied key up event for this column but whenever i'll try to edit employee address in the datagridview its firing Keyup event where i had been added numeric condition so i am getting exception,i have to call this event only if i am entering salary amount in datagridview salary column.

private void DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
            {
                TextBox t = (TextBox)e.Control;
                if (DataGridView.CurrentCell.ColumnIndex == DataGridView.Columns["Salary"].Index)
                {
                    t.KeyUp += new KeyEventHandler(t_KeyUp);
                }
            }
        }


    private void t_KeyUp(object sender, KeyEventArgs e)
            {
                //CheckForInt = false;
                try
                {
                    //My Code Condition applies here
                }
                catch(Exception)
                {
               }
}
Bioukh

You should use the DataGridView's KeyUp event instead.
I would do something like that :

private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
    if (dataGridView1.CurrentCell != null && dataGridView1.IsCurrentCellInEditMode && dataGridView1.CurrentCell.ColumnIndex == ColumnSalary.Index)
    {
        ...
    }
}

Using the editing control is often a bad idea and would lead you to many problems.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

DataGridView Numeric Only Cell?

From Dev

DataGridView Numeric Only Cell?

From Dev

jQuery using keydown/keyup/keypress event to fire only one time instead of multiple times when key held down

From Dev

Fire event when selecting a specific Tab Page C#

From Dev

DataGridView click event doesn't always fire

From Dev

Manually fire button click event in DataGridView

From Dev

Add dropdown for a specific cell in a datagridview

From Dev

Datagridview keyboard cursor to specific cell

From Dev

DataGridView align one specific Cell

From Dev

tinymce keyup event doesn't fire on tab key

From Dev

C# keyup event issue

From Dev

Fire a DataGrid Cell Edit Event with MVVM Design

From Dev

Add cell click event handler to datagridview?

From Dev

C# DataGridView Event to Catch When Cell (ReadOnly) Value has been changed by user

From Dev

C# DataGridView Event to Catch When Cell (ReadOnly) Value has been changed by user

From Dev

How to only fire event if flipswitch is manually switched

From Dev

Fire jQuery scroll event only once

From Dev

How to only fire event if flipswitch is manually switched

From Dev

Fire jQuery scroll event only once

From Dev

populating a specific cell in dataGridView from database

From Dev

How to identify the specific cell hovered over in DataGridView

From Dev

Find and move to a specific cell in a datagridview using textbox

From Dev

C# OpenXML-only specific cell styling for Excel export

From Dev

Catch KeyUp Event on WinForm C#

From Dev

WinForms DataGridView cell edit end event getting the cell

From Dev

How to colorize current cell only in DataGridView

From Dev

Multiline datagridview cell to display First Line only

Related Related

  1. 1

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

  2. 2

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

  3. 3

    DataGridView Numeric Only Cell?

  4. 4

    DataGridView Numeric Only Cell?

  5. 5

    jQuery using keydown/keyup/keypress event to fire only one time instead of multiple times when key held down

  6. 6

    Fire event when selecting a specific Tab Page C#

  7. 7

    DataGridView click event doesn't always fire

  8. 8

    Manually fire button click event in DataGridView

  9. 9

    Add dropdown for a specific cell in a datagridview

  10. 10

    Datagridview keyboard cursor to specific cell

  11. 11

    DataGridView align one specific Cell

  12. 12

    tinymce keyup event doesn't fire on tab key

  13. 13

    C# keyup event issue

  14. 14

    Fire a DataGrid Cell Edit Event with MVVM Design

  15. 15

    Add cell click event handler to datagridview?

  16. 16

    C# DataGridView Event to Catch When Cell (ReadOnly) Value has been changed by user

  17. 17

    C# DataGridView Event to Catch When Cell (ReadOnly) Value has been changed by user

  18. 18

    How to only fire event if flipswitch is manually switched

  19. 19

    Fire jQuery scroll event only once

  20. 20

    How to only fire event if flipswitch is manually switched

  21. 21

    Fire jQuery scroll event only once

  22. 22

    populating a specific cell in dataGridView from database

  23. 23

    How to identify the specific cell hovered over in DataGridView

  24. 24

    Find and move to a specific cell in a datagridview using textbox

  25. 25

    C# OpenXML-only specific cell styling for Excel export

  26. 26

    Catch KeyUp Event on WinForm C#

  27. 27

    WinForms DataGridView cell edit end event getting the cell

  28. 28

    How to colorize current cell only in DataGridView

  29. 29

    Multiline datagridview cell to display First Line only

HotTag

Archive