Click here to Skip to main content
14,738,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me,

It is a desktop application i used in validating event but
I am also used currentcelldirtystatechange event.
my problem is the current.. event is fired before checking
a validate cell or number data.

What should i do?

help!!!
:confused:
Posted
Updated 24-Apr-10 6:55am
v4

See here and here.
   
hope below code can help you in restricting datagridview


private void dtgView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dtgView.CurrentCell.ColumnIndex == dtgView.Columns["Column2"].Index & (e.Control != null))
            {
                TextBox tb = (TextBox)e.Control;
                tb.KeyPress += TextBox_KeyPress;
            }
        }





private void TextBox_KeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            //---if textbox is empty and user pressed a decimal char---
            if (((TextBox)sender).Text == string.Empty & e.KeyChar == (char) 46)
            {
                e.Handled = true;
                return;
            }
            //---if textbox already has a decimal point---
            if (((TextBox)sender).Text.Contains(Convert.ToString((char)46)) & e.KeyChar == (char)46)
            {
                e.Handled = true;
                return;
            }
            //if (!(char.IsDigit(e.KeyChar).ToString() ==","))
            if (!(e.KeyChar == 44) & !(e.KeyChar == 45))
            {
                if ((!(char.IsDigit(e.KeyChar) | char.IsControl(e.KeyChar) | (e.KeyChar == (char)46))))
                {
                    e.Handled = true;
                }
            }
        }
   
You should make a custom textbox cell and then use in datagridview. here is very good implementation Custom Numeric Edit Elements for DataGridView[^]
   

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