C# 将DataGridView列限制为小数点后2位
您好,我有一个gridview。我的要求是,当用户在一个字段中输入一个小数值时,它应该允许用户只输入2位小数位。输入2位小数位后,焦点应该转到下一个字段。 谢谢,试试这个 试试这个: 编辑: 试试这个 试试这个: 编辑:C# 将DataGridView列限制为小数点后2位,c#,datagridview,C#,Datagridview,您好,我有一个gridview。我的要求是,当用户在一个字段中输入一个小数值时,它应该允许用户只输入2位小数位。输入2位小数位后,焦点应该转到下一个字段。 谢谢,试试这个 试试这个: 编辑: 试试这个 试试这个: 编辑: 我得到了解决方案,Geetha,我为我的DataGridView处理了事件编辑控制显示。 代码如下: private void Lot_dataGridView_EditingControlShowing(object sender, DataGridViewEdi
我得到了解决方案,Geetha,我为我的DataGridView处理了事件编辑控制显示。 代码如下:
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\u 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.
}
我得到了解决方案,Geetha,我处理了DataGridView的事件编辑控制显示。 代码如下:
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\u 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.
}
我正在创建一个winform,我想实现上面的问题。我正在创建一个winform,我想实现上面的问题。嗨,Geetha,实际上,我想在用户编辑列时检查小数位。是否有任何事件会在焦点列上输入的每个数字上调用。基本上,我想屏蔽一些Datagridview列。我正在动态创建列。所以我认为默认情况下它是DataGridViewTextBoxColumn,然后尝试为该文本框动态创建文本更改事件以进行验证Hi Geetha,实际上,我想在用户编辑列时检查小数位。是否有任何事件会在焦点列上输入的每个数字上调用。基本上,我想屏蔽一些Datagridview列。我正在动态创建列。因此,我认为默认情况下,它是DataGridViewTextBoxColumn,然后尝试为该文本框动态创建文本更改事件以进行验证我做了abatishchev,但它说“你可以在2天内接受你自己的答案”我做了abatishchev,但它说“你可以在2天内接受你自己的答案”