Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to clear datagridview typed cell value in c# .net windows application?

I have a datagridview in my application i am validating our datagridview for numneric value,
I am using this code:-
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            
                DataGridViewTextBoxCell cell = dataGridView1[6, e.RowIndex] as DataGridViewTextBoxCell;
                if (cell != null)
                {
                    if (e.ColumnIndex == 6)
                    {
                        char[] chars = e.FormattedValue.ToString().ToCharArray();
                        foreach (char c in chars)
                        {
                            if (char.IsDigit(c) == false)
                            {
                                MessageBox.Show("You have to enter digits only");
                                e.Cancel = true;
                                break;
                            }
                        }
                    }
                }
            }

        }

But i have a problem with this, when we typed in cell so it did not clear cell after the message show,
I have to press, Backspace key for clear the cell.

I want to automatically cleared after wrong entry or "MessageBox.Show("You have to enter digits only");" this message show.

How it can be possible?

Please help me.

Thanks in Advance
Ankit Agarwal
Software Engineer
Posted
Updated 5-Sep-13 1:19am
v2
Comments
[no name] 5-Sep-13 7:06am    
What? Did you try setting the cell value to string.Empty?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900