检测 Datagridview 控件中的字母或数字键并将处理后的键发送到文本框 VB.BET
我正在开发一个包含 datagridview 和文本框的表单,我需要 datagridview 检测字母表中的任何字母或数字,然后选择输入并将按下的键发送到输入。
我找不到任何解决方案,提前致谢。
I'm working on a Form that contains a datagridview and textbox, I need the datagridview detect any letter of the alphabet or numbers, then select the input and send the key pressed to input.
I can not find any solution for this, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您需要将事件处理程序附加到正在接收响应 KeyPress 事件的数据的单元格编辑控件。这可以通过处理 EditingControlShowing 事件来完成。
以下是执行此操作的一些基本代码:
您还可以响应其他事件,例如 KeyDown,但通常首选 KeyPress,因为它为您提供带有事件参数的 Char。对于像 KeyDown 这样的事件,您将拥有 KeyCodes,它不允许您轻松判断输入是大写还是小写。
You will need to attach an event handler to the cell editing control that is receiving the data that will respond to the KeyPress event. This can be done by handling the EditingControlShowing event.
Here is some basic code that does this:
There are other events that you can respond to such as KeyDown but KeyPress is generally preferred since it gives you a Char with the event args. With events like KeyDown you will have KeyCodes instead, which don't allow you to easily tell if the input was upper or lower case.