Datagridview标题:如何确定我右键单击的标题 [英] Datagridview Headings: How to Determine which heading I right clicked on
问题描述
Good Day
我已经创建了一个带有Datagridview的窗体.我想右键单击Datagridview上的特定标题,然后打开一个新表单.
我已经在Datagridview的ColumnHeaderMouseClick事件上编写了以下代码.
Good Day
I have created a Form with a Datagridview on it. I want to Right click on a specefic heading on my Datagridview and it open a new form.
I have written the following code on the ColumnHeaderMouseClick Event on the Datagridview.
private void dtgAllIngdetTerminals_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (dtgAllIngdetTerminals.Columns["TerminalID"].HeaderText == "TerminalID")
{
frmFilter frmthree = new frmFilter();
frmthree.ShowDialog();
}
}
}
目前,当我右键单击DatagridView中的任何标题时,它正在打开一个新表单.在我的代码不正确的地方有任何建议吗?
At the moment, when I right click on any heading in the DatagridView it is opening a new form. Any suggestions where my code is incorrect?
推荐答案
替换
if (dtgAllIngdetTerminals.Columns["TerminalID"].HeaderText == "TerminalID")
与
with
if (dtgAllIngdetTerminals.Columns["TerminalID"].Index == e.ColumnIndex)
如果您的问题得到解决,则您可以接受并投票解决该问题,否则可以发布您的查询,以便其他用户可以知道
PES
If your problem is solved you may accept and vote the solution, otherwise post your queries, so that other users can know
PES
这篇关于Datagridview标题:如何确定我右键单击的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!