GridControl 删除选中行

来源:互联网 发布:滨州行知中学招生简章 编辑:程序博客网 时间:2024/06/05 09:21
共有两种方式,第一种通过制定行的行号删除,如下:
</pre><pre class="csharp" name="code">BGV.DeleteRow(BGV.FocusedRowHandle);
(上面的代码使用与WPF)
MessageBox.Show(DGList.GetFocusedRowCellDisplayText("BarCode"));//获取当前选中行指定列的数据
第二种,直接删除
<pre class="csharp" name="code">BGV.DeleteSelectedRows();
上面的代码适用于WinFrom

大笑

最后通过数据库把变动的数据提交了就可以了!

格式如下:

Add为数据库连接地址

(下面的代码为WPF。WinFrom可能需要少量修改)

  private void SaveChange()        {            try            {                BGV.CloseEditor();                string select = string.Format("SELECT [ID],[材料类型],[品牌]FROM [dbo].[产品免检表]");                string update = string.Format("UPDATE [dbo].[产品免检表] SET 材料类型=@材料类型,品牌=@品牌 WHERE ID=@OLDID");                string delete = string.Format("DELETE FROM [dbo].[产品免检表] WHERE ID=@ID");                string insert = string.Format("INSERT INTO [dbo].[产品免检表] (材料类型,品牌)VALUES(@材料类型,@品牌)");                SqlConnection Connection = new SqlConnection(Add);                SqlDataAdapter Adapter = new SqlDataAdapter();                SqlCommand Command = new SqlCommand(select, Connection);                Adapter.SelectCommand = Command;                Command = new SqlCommand(insert, Connection);                Command.Parameters.Add("@材料类型", SqlDbType.NVarChar, 50, "材料类型");                Command.Parameters.Add("@品牌", SqlDbType.NVarChar, 50, "品牌");                Adapter.InsertCommand = Command;                Command = new SqlCommand(update, Connection);                Command.Parameters.Add("@材料类型", SqlDbType.NVarChar, 50, "材料类型");                Command.Parameters.Add("@品牌", SqlDbType.NVarChar, 50, "品牌");                Command.Parameters.Add("@ID", SqlDbType.BigInt, 10, "ID");                SqlParameter Parameter = Command.Parameters.Add("@OLDID", SqlDbType.BigInt, 10, "ID");                Parameter.SourceVersion = DataRowVersion.Original;                Adapter.UpdateCommand = Command;                //删除命令                Command = new SqlCommand(delete, Connection);                Parameter = Command.Parameters.Add("@ID", SqlDbType.BigInt, 10, "ID");                Parameter.SourceVersion = DataRowVersion.Original;                Adapter.DeleteCommand = Command;                Adapter.Update(DTT.Tables[0]);                DTT.AcceptChanges();                Refresh();                System.Windows.MessageBox.Show("保存成功");            }            catch (Exception err)            {                System.Windows.MessageBox.Show(err.Message);            }        }




0 0
原创粉丝点击