在datagridview中单击paricular单元格时如何运行事件 [英] how run a event when click on paricular cell in datagridview
问题描述
朋友们。
抱歉英语不好。
i有一个表格。有一个网格视图。
i添加了一个新专栏to datagrid .name of column是image,
它的类型是图像,它有一张如下图所示。
http://upload.tehran98.com/img1/4pdunfwa7glm0jnagmvb.jpg [ ^ ]
我的问题:当我点击每个单元格时代码被执行。
***我想要的是当我只点击图像单元格时我的代码被执行。
这是我在CellContentClick事件上的代码类型。(用于删除行)但是没有回答。
请帮忙。
private void elDataGridView1_CellContentClick(object sender,DataGridViewCellEventArgs e)
{
DialogResult dr;
dr = MessageBox.Show(你要删除,del,
我的代码....
... ..
....
}
hi freinds.
sorry for poor english.
i have a form .there is a gridview into that.
i added a new column to datagrid .name of column is "image",
its type is image and it has a photo like below.
http://upload.tehran98.com/img1/4pdunfwa7glm0jnagmvb.jpg[^]
my problem : when i click on every cell the code is executed .
*** i want that when i click only the image cell my code be executed.
this is type of my code on CellContentClick event .(for deleting a row) but does not answer.
please help.
private void elDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DialogResult dr;
dr = MessageBox.Show("do you want to delete", "del",
my code ....
.....
....
}
推荐答案
检查ColumnIndex并只做代码是正确的列:
Check the ColumnIndex and only do the code if it is the correct column:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
int i = dgv.Columns["MyImageColumn"].Index;
if (i == e.ColumnIndex)
{
// It's the right column!
}
}
}
这篇关于在datagridview中单击paricular单元格时如何运行事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!