Reputation: 1485
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
Upvotes: 1
Views: 3087
Reputation: 1485
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.
}
Upvotes: 1
Reputation: 5343
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
Upvotes: 0