如何在Windows窗体中禁用标题单击 [英] how to disable header click in windows forms
本文介绍了如何在Windows窗体中禁用标题单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家,
我有一个网格视图,点击单元格我正在访问该行的id。我的问题是当我点击标题时出现异常..: (
有没有办法在标题上禁用点击事件.. ??
如何解决这个问题......?
Hi experts,
I have a grid view and on clicking the cell i am accessing the id of that row.my problem is when i am clicking on the header am getting an exception..:(
Is there any way to disable click event on header..??
How to solve this... ? ? ?
推荐答案
嗨HK33,
虽然你的问题很糟糕但我试着开始猜测可能会解决你的问题。你期待有人为你工作/思考,但是你不用费心去制定你的问题 - 请参阅OriginalGriffs评论。但是对于这种行为你并不孤单在这个论坛上 - 我只是可以'得到使用...
那就是说,让我们试着找到你的问题:
我假设(那些你不认为有人应该知道以帮助你的东西):
*你使用System.Windows.Forms.DataGridView
*您使用的是CellClick
的事件System.Windows.Forms.DataGridView
*当你试图获取一个单元格时会发生异常使用CellClick处理程序(方法)中的EventArgs获得的索引
所以诀窍可能只是为你的处理程序添加一些逻辑。
Hi HK33,
Although your question is quite "BAD" I try to start the guessing to work out what may be your problem. You are expecting someone to "work/think" for you, but you don't bother to formulate your question with a little effort - see OriginalGriffs comment. But with this "behaviour" you are not alone on this forum - I just can't get "used" to it...
That said, let's try to find your Problem:
I assume (those things you didn't think someone should know in order to help you):
* You use aSystem.Windows.Forms.DataGridView
* You are using theCellClick
Event of yourSystem.Windows.Forms.DataGridView
* Your exception happens when you try to get a cell with the indices you got from the EventArgs inside a CellClick handler (method)
So the trick could be just to add some logic to your handler.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
// No row was clicked (e.g. Header)
if (e.RowIndex < 0)
{
}
// No column was clicked (e.g. RowHeader)
else if (e.ColumnIndex < 0)
{
}
// valid cell
else
{
}
}
如果这不能解决你的问题问题试着改善你的问题,并显示有问题/相关的代码。
亲切的问候
Johannes
If this does not solve your problem try to improve your question and show the problematic/relevant code.
Kind regards
Johannes
你好,
你可以在行点击事件上处理它。
在行点击或单击鼠标上写代码事件
Hello,
You can handle it on row click event.
write code on row click or cell click event
e.handle=false;
这篇关于如何在Windows窗体中禁用标题单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文