Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i want to perform validations on DatagridviewTextboxColumn
suppose if i have 5 Textboxes inside DataGridView1->Column1,
i want to accept only 2 decimal places on each textbox,
and also
1st Textbox Value < 2nd Textbox Value
2nd Textbox Value < 3rd Textbox Value
3rd Textbox Value < 4th Textbox Value
4th Textbox Value < 5th Textbox Value

I want some help to acheive my task..
Any idea plz let me know.

The below is my Code
C++
DataTable dtGridEdit = new DataTable();
DataRow dr = null;
DataGridViewTextBoxColumn TxtCol = new DataGridViewTextBoxColumn();
private void FillGridView()
{
        for (int i = 0; i < 4; i++)
        {
                dr = dtGridEdit.NewRow();
                dtGridEdit.Rows.Add(dr);
        }
        dgridEdit.DataSource = dtGridEdit;
        dgridEdit.Columns.Add(TxtCol);
}

 private void dgridEdit_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            try
            {
                if (e.Control.GetType().BaseType.Name == "TextBox")
                    mobjInnerTextBox = (TextBox)e.Control;
                 mobjInnerTextBox.KeyPress += new KeyPressEventHandler(mobjInnerTextBox_KeyPress);
            }
            catch (Exception ex)
            {
                DataClass.LogError(ex);
            }
        }
 bool DotEntered;
        private void mobjInnerTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (mobjInnerTextBox.Text == "")
                {
                    DotEntered = false;
                }
                if (e.KeyChar == '.' && DotEntered == false)
                {
                    e.Handled = false;
                    DotEntered = true;
                }
                else if (char.IsDigit(e.KeyChar) == true || e.KeyChar == (char)Keys.Back)
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                DataClass.LogError(ex);
            }
        }

Regards,
Pawan.
Posted
Updated 13-Jul-10 4:37am
v3
Comments
Sandeep Mewara 13-Jul-10 10:39am    
Preview (just before submitting the question or an answer), shows exactly how your text is going to be displayed. Use that as a reference before clicking submit. Modify it such that it appears as desired.

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