嗨我有一个gridview.My要求是当用户在字段中输入一个十进制值时,它应该允许用户只输入2位小数位。输入2位小数后,焦点应该到达下一个字段。 感谢
答案 0 :(得分:1)
我得到了解决方案Geetha,我为DataGridView处理了EditingControlShowing事件。 代码如下:
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);
}
}
}
然后我处理了textbox_TextChanged事件。
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.
}
答案 1 :(得分:0)
试试这个。
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
试试这个:
http://canbal.com/view.php?sessionid=%2BAmPfTAGUB81PWUrGHP0v3%2BMvlGZLQ7gccyIsH9uc7g%3D
编辑:
http://weblogs.asp.net/rweigelt/archive/2007/02/12/1647400.aspx