dataGridView1如何进行输入判断 dataGridView1 中有三列, Sum1,Sum2 ,Sum3其中 Sum3=Sum1+Sum2Sum1 < Sum2如何实现在Sum1中输入的值一定要小于Sum2,当Sum1中输入的值一定要大于Sum2会提示输入错误。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是验证datagridview 单元里面只准输入数字,你参照这个自由发挥吧..#region 进入编辑状态时 TextBox txtCell; private void dgvSettleInfo_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { txtCell = new TextBox();//单元格进入编辑状态时实列化文本框 //单元格强制转化成文本框 txtCell = (TextBox)e.Control; //绑定按键事件 txtCell.KeyPress += new KeyPressEventHandler(txtCell_KeyPress); } #endregion#region 文本框的按键事件 private void txtCell_KeyPress(object sender,KeyPressEventArgs e) { try { //输入的只准是数字,长度为7位数 if ((char.IsNumber(e.KeyChar)) && txtCell.Text.Length < 7) { e.Handled = false; } else { e.Handled = true; } if ((e.KeyChar == (char)8))//允许输入退格 { e.Handled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion //在DataGridView1_CellEndEdit中if (!DBNull.Value.Equals(dataGridView.CurrentRow.Cells["sum1"].Value) && !DBNull.Value.Equals(dataGridView.CurrentRow.Cells["sum2"].Value)) {if(dataGridView.CurrentRow.Cells["sum1"].Value) < dataGridView.CurrentRow.Cells["sum2"].Value}{ dataGridView.CurrentRow.Cells[sum3].Value =dataGridView.CurrentRow.Cells["sum1"].Value) + dataGridView.CurrentRow.Cells[sum2].Value);else{messageBox.Show("错误");} } 请问怎么在C#里面动态申请内存空间用于存储中间数据呢? dev控件如何汉化。 一个treeview循环遍历的简单问题,请高手帮忙 面试没做对的题,求教算法 文件是放到服务器的共享目录中,还是放在数据库中 。net中没有水晶报表的编辑器~~!怎么追加? vs2005页面返回值的问题 集合属性该怎么写? (c#)请问谁知道如何读取文本文件中的指定行数的内容?? C#.NET 2003 启动不了测试 报错:无法自动将服务器设置为正确的调试状态。 附加问题:IIS7.0怎么降为IIS6.0。 js select 缺少对象 c# 转换 vb.net 出现错误 请熟悉vb.net c# 的朋友看看
TextBox txtCell;
private void dgvSettleInfo_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
txtCell = new TextBox();//单元格进入编辑状态时实列化文本框
//单元格强制转化成文本框
txtCell = (TextBox)e.Control;
//绑定按键事件
txtCell.KeyPress += new KeyPressEventHandler(txtCell_KeyPress); }
#endregion#region 文本框的按键事件 private void txtCell_KeyPress(object sender,KeyPressEventArgs e)
{
try
{
//输入的只准是数字,长度为7位数
if ((char.IsNumber(e.KeyChar)) && txtCell.Text.Length < 7)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
if ((e.KeyChar == (char)8))//允许输入退格
{
e.Handled = false;
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
} #endregion
if (!DBNull.Value.Equals(dataGridView.CurrentRow.Cells["sum1"].Value) && !DBNull.Value.Equals(dataGridView.CurrentRow.Cells["sum2"].Value))
{
if(dataGridView.CurrentRow.Cells["sum1"].Value) < dataGridView.CurrentRow.Cells["sum2"].Value}
{ dataGridView.CurrentRow.Cells[sum3].Value =dataGridView.CurrentRow.Cells["sum1"].Value) + dataGridView.CurrentRow.Cells[sum2].Value);
else
{
messageBox.Show("错误");
} }