views:

75

answers:

2

Hi i have a gridview.My requirement is when the user enters a decimal value in a field, it should allow user to enter only 2 decimal place digits.After entering 2 decimal place the focus should get to next field. Thanks

A: 

Hi,

Try this.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx

http://www.dotnetspark.com/Forum/669-problem-datagridview-cell-validation-c-sharp.aspx

Try This:

http://canbal.com/view.php?sessionid=%2BAmPfTAGUB81PWUrGHP0v3%2BMvlGZLQ7gccyIsH9uc7g%3D

Edit:

http://weblogs.asp.net/rweigelt/archive/2007/02/12/1647400.aspx

Geetha
hi Geetha, actually i want to check the decimal place while user is editing the column.Is there any event which will get called on every number entered on the focused column.
Nipun
Basically i want masking to some Datagridview columns.
Nipun
Are you editing the cell value with a textbox?
Geetha
I am creating the columns dynamically. So i think by default it is DataGridViewTextBoxColumn
Nipun
Then try to create text changed event for that text box dynamically for validation
Geetha
i got the solution.Thanks for help Geetha. Keep Coding ...
Nipun
A: 

I got the solution Geetha, I handled the event EditingControlShowing for my DataGridView. The code is below:

private void Lot_dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    if (e.Control is DataGridViewTextBoxEditingControl)
    {
        if (ColIndex == "2") // this colIndex i got it from CellEnter event.
        {
            DataGridViewTextBoxEditingControl te = (DataGridViewTextBoxEditingControl)e.Control;
            te.TextChanged += new EventHandler(textbox_TextChanged);
        }
    }
}

and then i handled the textbox_TextChanged event.

void textbox_TextChanged(object sender, EventArgs e)
{
    TextBox tb = (TextBox)sender;
    MessageBox.Show(tb.Text);
    // Do your changes here.
    // To Change focus from the current cell use
    SendKeys.Send("{TAB}"); // to give focus to next cell in the same row.
}
Nipun
Don't forget to accept your own answer as correct
abatishchev
i did that abatishchev but its says "u can accept ur own answer in 2 days"
Nipun