【发布时间】:2018-02-04 16:45:21
【问题描述】:
我有实验室请求窗口,我可以稍后创建新请求 我需要更新此订单 我创建了更新窗口,我从 datagrid 视图中的数据库中读取了订单详细信息,我需要添加新项目datagridview,但是当我添加新行时出现错误,现有行被删除并添加新行我的代码有什么错误,我正在添加新行。 如何添加新行并保留现有行,还要检查附件 datagridview 图像,然后按 enter 键和 datagridview1 图像,然后按输入其添加新行并删除从数据库中获取的现有行。
private void textAmount_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && textQty.Text != string.Empty && textAmount.Text != string.Empty)
{
if (chkcash1.Checked == true)
{
textDiscount.Focus();
}
if (chkcash1.Checked == false)
{
for (int i = 0; i < TestsDataGrid.Rows.Count - 1; i++)
{
if (TestsDataGrid.Rows[i].Cells[0].Value.ToString() == textTestId.Text)
{
MessageBox.Show("This test added already ", "Duplicate Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
DataRow r = dt.NewRow();
r[0] = textTestId.Text;
r[1] = textName.Text;
r[2] = textPrice.Text;
r[3] = textQty.Text;
r[4] = textAmount.Text;
r[5] = textTotal.Text;
dt.Rows.Add(r);
TestsDataGrid.DataSource = dt;
textTestId.Clear();
textName.Clear();
textPrice.Clear();
textAmount.Clear();
textTotal.Clear();
btnSearch.Focus();
textOrderTotal.Text = (from DataGridViewRow row in TestsDataGrid.Rows
where row.Cells[4].FormattedValue.ToString() != string.Empty
select Convert.ToDouble(row.Cells[4].FormattedValue)).Sum().ToString();
}[datagridviewimage][1]
【问题讨论】:
-
标点是你的朋友。
-
是的,我没有超过第三行
-
我什至用文字来编辑它,但我仍然感到困惑。请远离咖啡!
-
在添加新行之前 dt 有多少行?并且 dt 是您用作数据网格的数据源的源?
-
@Saruman 对不起我的英语不好我英语不流利我会尝试订购问题
标签: c# datagridview