C# DataGridvew和contextMenuStrip1控件实现表格删除
2018-03-05 09:18
447 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DataGrivew.Delete_Row
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“e_TestDataDataSet.Employee”中。您可以根据需要移动或删除它。
this.employeeTableAdapter.Fill(this.e_TestDataDataSet.Employee);
}
private int RowIndex = 0;
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
{
this.dataGridView1.Rows[e.RowIndex].Selected = true;//启动点击选中
RowIndex = e.RowIndex;//读取点击启动行号
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1];//设置为单行选中
this.contextMenuStrip1.Show(this.dataGridView1,e.Location);//设置contextMenuStrip1控件显示和dataGriView控件绑定
contextMenuStrip1.Show(Cursor.Position);//设置contextMenuStrip1控件的显示座标
}
}
private void 删除行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if(!this.dataGridView1.Rows[RowIndex].IsNewRow)
{
this.dataGridView1.Rows.RemoveAt(RowIndex);//移除行
}
}
}
}
1.添加dataGridView控件和contextMenuStrip控件
2.设置CellMouseDown属性。
相关文章推荐
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- asp.net DataGridTree表格树控件 下拉树 DropTree c# .net
- JS调用C#后台代码---JS实现DataGrid“全选”、“反选”、调用后台代码批量删除数据
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- C# windows mobile中实现控件的动态绘制与动态删除
- ASP.NET基础教程-DataGrid表格控件-DataGrid实现双表头
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- JS调用C#后台代码---JS实现DataGrid“全选”、“反选”、调用后台代码批量删除数据
- WinForm中DataGridView控件通过复选框实现多条记录的删除 c#2005
- 在c#中利用dataGrid实现数据库的多表查询,修改,删除
- C# 实现对PPT插入、编辑、删除表格
- JS调用C#后台代码---JS实现DataGrid“全选”、“反选”、调用后台代码批量删除数据
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- jQuery 实现添加表格行,删除行,调用日期控件
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- C# 实现对PPT插入、编辑、删除表格
- C#中删除任意控件任意事件的事件列表的实现!