简体   繁体   English

当按0或1按下Delete按钮时,隐藏行而不是删除

[英]Hide row instead of deleting when Delete button is pressed on the basis of 0 or 1

I need to Hide the row from Gridcontrol instead of deleting the data from data source. 我需要从Gridcontrol隐藏行,而不是从数据源中删除数据。

eg when user deletes the row a query runs which inserts the 0 value in my table and Shows the table with rows whose value is not null. 例如,当用户删除行时,将运行查询,该查询将0值插入到我的表中,并显示该表及其值不为null的行。

I have tried using the code below. 我尝试使用下面的代码。 But i cant seem to run it. 但是我似乎无法运行它。

del = 1;

ColumnView view = gridControl1.FocusedView as ColumnView;
view.FocusedRowHandle = user_typeTableAdapter1.Insert_del(del);
view.SelectRow(view.FocusedRowHandle);

The error occurs that I cannot put del only in table adapter although i inserted self defined query. 发生错误,尽管我插入了自定义查询,但我无法仅将del放在表适配器中。
This is the main problem that is occurring and i don't have so much help in this matter. 这是正在发生的主要问题,在这件事上我没有太多帮助。

Hi, The answer to this question is as given below. 嗨,这个问题的答案如下。

Actually I was inserting the value instead of updating it. 实际上,我是在插入值而不是更新它。 All i had to do was to run a query and execute it when delete is called. 我要做的就是运行查询并在调用delete时执行它。

Note this is to demonstrate the data deleted from gridView in Devexpress 注意,这是为了演示在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();
        }
}

Now for gridView part 现在为gridView零件

  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);
                    }
                }

            }
        }

Now every time user delete a row it will get hidden instead of being deleted. 现在,每次用户删除行时,它将被隐藏而不是被删除。

Actually it was requirement by a user. 实际上,这是用户的要求。 So i had to implement it. 所以我不得不实施它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM