日期:2014-05-18  浏览次数:20912 次

这样的需求该如何实现?高分求代码示例
在 DataGridView 下方拖放两个 TextBox (TextBox1输入编号,TexBox2 输入数量)控件。
TextBox1 的 KeyDown 事件中判断是否输入回车,如是即将 TextBox2 设为信点, TextBox2.Text 默认为 1。
TextBox2 的 KeyDown 事件中判断是否输入回车,如是即读取产品信息加往 DataGridView 绑定的 DataTable 中添加详细的数据。焦点回到 TextBox 1 并重置两个 TextBox 的 Text 属性。


如此反复就完成了一张表单,求代码示例



当我在DataGridView.Rows[0].Cells[1]输入数据'7.01.01.01.0021'后,根据这个物料代码(FFullNumber)调用存储过程"t_BOM1",
在DataGridView.Rows[0].Cells[2]中显示FInterID,
在DataGridView.Rows[0].Cells[3]中显示FParentID,
在DataGridView.Rows[0].Cells[4]中显示FName

当我在DataGridView.Rows[1].Cells[1]输入数据'7.01.01.01.0031'后,根据这个物料代码(FFullNumber)调用存储过程"t_BOM1",
在DataGridView.Rows[1].Cells[2]中显示FInterID,
在DataGridView.Rows[1].Cells[3]中显示FParentID,
在DataGridView.Rows[1].Cells[4]中显示FName

…………………………………………

当我在DataGridView.Rows[N].Cells[1]输入数据'7.01.01.01.0031'后,根据这个物料代码(FFullNumber)调用存储过程"t_BOM1",
在DataGridView.Rows[N].Cells[2]中显示FInterID,
在DataGridView.Rows[N].Cells[3]中显示FParentID,
在DataGridView.Rows[N].Cells[4]中显示FName

------解决方案--------------------
TextBox control;
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox cotrol = new TextBox();
cotrol = (TextBox)e.Control;
cotrol.KeyPress+=new KeyPressEventHandler(cotrol_KeyPress);
}
private void cotrol_KeyPress(object sender, KeyPressEventArgs e) 
{
if (char.IsNumber(e.KeyChar) && cotrol.Text.Length < 10)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}




private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "")
{
string s=e.FormattedValue.ToString()
}
}