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
2010-09-21 05:36:45
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
2010-09-21 05:58:44
Basically i want masking to some Datagridview columns.
Nipun
2010-09-21 06:23:47
Are you editing the cell value with a textbox?
Geetha
2010-09-21 06:31:17
I am creating the columns dynamically. So i think by default it is DataGridViewTextBoxColumn
Nipun
2010-09-21 06:39:55
Then try to create text changed event for that text box dynamically for validation
Geetha
2010-09-21 06:41:37
i got the solution.Thanks for help Geetha. Keep Coding ...
Nipun
2010-09-21 06:57:51
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
2010-09-21 06:57:10
i did that abatishchev but its says "u can accept ur own answer in 2 days"
Nipun
2010-09-21 07:08:52