我有一个dataGridView
,我试图在单击一个单元格时触发一个事件。我尝试使用以下事件但无效:
private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e) { //dosomething }
private void dataGridView2_CellMouseClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //dosomething }
private void dataGridView2_CellMouseClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { //dosomething } private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //dosomething }
我确保的名称匹配,但这些事件都没有在调试器中触发或显示。我错过了什么吗?
答案 0 :(得分:1)
在设计器中选择网格,转到属性,单击属性中的“事件”按钮,然后双击CellClick事件右侧的值单元格 要么 转到designer.cs文件并查看gridview的所有属性的定义,并查看是否存在这样的任何行
gridview.CellClick + = new EventHandler(dataGridView2_CellClick);
如果它不存在则添加它。