在datagridview中的单元格或列标题上单击 [英] Perform Click on a cell or column header in a datagridview

查看:79
本文介绍了在datagridview中的单元格或列标题上单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道没有datagridview.performclick事件.
但是我有一个单元格是(0)和列(0),需要
扫描文本框中的条形码,并以编程方式单击该列.
我已经搜索了Web和MS论坛,但找不到任何有效答案.
是否有可能在datagridview中的特定单元格或列上调用执行单击?这是用于vb net.当然,用C#回答也将有所帮助.

I know that there is no datagridview.performclick event.
But I have a cell that is (0) and column (0)and need to
scan a barcode in a textbox and have that column programatically clicked.
I have searched the web and MS forums but can''t find any working answers.
Is it possible at all to call a perform click on a specific cell or column in a datagridview? This is for vb net. Of Course an answer in C# would help too.

推荐答案

您可以通过一些JavaScript轻松实现.

制作3个隐藏字段:
You can do it easily with a bit of javascripting.

Make 3 hidden fields:
<input runat=server type=hidden id=inhAction />
<input runat=server type=hidden id=inhRow />
<input runat=server type=hidden id=inhColumn />



和一个javascript函数:



and a javascript function:

function cellClicked(row, column){
myForm.inhAction.value = "CELLCLICKED";
myForm.inhRow.value = row;
myForm.inhColumn.value = column;
myForm.submit();
}



并在gridview的RowDataBound事件中为每个
设置javascript调用 单元格:



and in the gridview''s RowDataBound event setup the javascript call for every
cell:

myCell.Attributes["onclick"]=String.Format("cellClicked({0},{1})",
myCellRow, myCellColumn);



当您单击一个单元格时,您将获得一个回发.您可以告诉
回传是由单元格单击inhAction引起的,您可以
从inhRow和inhColumn获取行号和列号.

如果有帮助,请 投票 接受答案 .



When you click a cell, you will get a postback. You can tell taht the
postback is caused by a cell click by looking in the inhAction and you can
get the row and the column numbers from the inhRow and inhColumn.

Please vote and Accept Answer if it Helped.


这篇关于在datagridview中的单元格或列标题上单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆