最近要右键点击然后直接改值,
首先获取选中的行和列的索引,先给dataGridView1绑定CellMouseUp事件
然后创建菜单并且绑定,这个百度就行了,给菜单一个事件,之后再去改事件就行了
int yjh =-1;int yjl =-1;private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e){if (e.Button == MouseButtons.Right){if (e.RowIndex >= 0){yjh = e.RowIndex;yjl = e.ColumnIndex;}}}private void 修改ToolStripMenuItem_Click(object sender, EventArgs e){string c = dataGridView1.Columns[yjl].Name;if (c == "是不是想要修改的位置" ){dataGridView1.Rows[yjh].Cells[yjl].Value = "修改的值";}}