我需要从Gridcontrol中隐藏行,而不是从数据源中删除数据。
例如,当用户删除行时,运行一个查询,该查询将在我的表中插入0值,并显示包含值不为null的行的表。
我已经尝试使用下面的代码。但我似乎不能运行它。
del = 1;
ColumnView view = gridControl1.FocusedView as ColumnView;
view.FocusedRowHandle = user_typeTableAdapter1.Insert_del(del);
view.SelectRow(view.FocusedRowHandle);虽然我插入了自定义查询,但出现了不能将del只放入表适配器中的错误。
这是正在发生的主要问题,在这件事上我没有太多的帮助。
发布于 2019-08-29 05:11:23
嗨,这个问题的答案如下所示。
实际上,我是在插入值,而不是更新它。,。我所要做的就是运行一个查询,并在调用delete时执行它。
注意:这是为了演示在Devexpress中从gridView删除的数据
private void Delete(){
try
{
conn.Open();
ColumnView view = gridControl1.FocusedView as ColumnView;
int id = Convert.ToInt32(gridView1.GetDataRow(view.FocusedRowHandle)["product_id"]);
string query = "UPDATE product SET del =@product_del where product_id= @id";
int del = 1;
SqlCommand sc = new SqlCommand(query, conn);
sc.Parameters.AddWithValue("@product_del", del);
sc.Parameters.AddWithValue("@id", id);
sc.ExecuteScalar();
sc.Dispose();
conn.Close();
}
}用于gridView部件的
Now
private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Delete)
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this row, it will permanently delete the data", "Delete?", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
ColumnView view = gridControl1.FocusedView as ColumnView;
view.CloseEditor();
{
Delete();
view.UpdateCurrentRow();
product_viewTableAdapter1.Fill(allDataSets1.Product_view);
}
}
}
}现在,每次用户删除一行时,它都会被隐藏,而不是被删除。
实际上,这是用户的要求。所以我不得不实现它。
https://stackoverflow.com/questions/56984363
复制相似问题