海海日记-冯海滨博客

您现在的位置是:首页 > C# > 正文

C#

datagridvies 通过删除列的删除按钮 删除行

happyfhb2014-03-22C#1494
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == this.dataGridView1.Columns["del"].Index)
            { //判断列索引是不是删除按钮
                int rows = dataGridView1.CurrentRow.Index; //得到当前行的索引
                string id = dataGridView1.Rows[rows].Cells[6].Value.ToString(); //得到表的主键ID,就是上表中的userid
                if (id != null && id != "" && MessageBox.Show("您确定要删除吗?", "重要提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.OK)
                {
                    dataGridView1.Rows.RemoveAt(rows);
                    //执行删除方法
                    //重新绑定数据(刷新列表)
                }
            }
        }


平淡中储蓄成长

发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~