开发者

Restrict the up and down key on datagridview

I have a开发者_StackOverflow中文版 datagridview on form. When user clicks on a data on datagridview, program calculates something. But user also can select data by using up and down arrow key on keybord. I dont want this. Because i put my calculating codes in Datagridview_CellClick events. If i also put it in Datagridview_SelectionChanged event, program calculates it twice when user clicks on datagridview. I mean i want to protect user to navigate the datagridview by pressing up and down arrow key by keybord. Is there any way?


Must your calculation happen when the user clicks within the DataGridView? If your calculation is based upon the data within the grid then you would be better off using the CellValueChanged or CellValidateEvents to trigger the calculation.

It wasn't 100% clear from your question whether you did or did not want the calculation to happen on the up and down keypress. The reason it is unclear is the the CellClick event does not occur on an up or down arrow keypress, so that should not be a problem.

If you want to calculate on these keypresses you could either use the CellEnter event or handler the KeyPress - the advantage of the keypress is that you can check there which key was actually pressed if needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜