简体   繁体   English

当在另一个dataGridView中按下箭头键时,更改一个dataGridView中的行

[英]change the row in one dataGridView when arrow Keys are pressed in other dataGridView

I went into problem: I have two DataGridView on my form MAIN and SUB, now here is what I want to do that if MAIN DataGridView cell is in edit mode and user press the down arrow then instead of going down to next row in MAIN DataGridView it should step to next row in SUB DataGridView 我遇到了问题:我的表单MAIN和SUB上都有两个DataGridView ,如果MAIN DataGridView单元格处于编辑模式并且用户按下向下箭头,而不是下移至MAIN DataGridView下一行,那么我现在想做的就是它应该转到SUB DataGridView下一行

I have created an event on EditingControlShowing by handling the PreviewKeyDown but it works only if there is one row in MAIN DataGridView or i am on the Last row in MAIN dataGridView but if there are more then one row in MAIN DataGridView then if i press Arrow Up or Arrow Down it moves through MAIN DataGridView Rows only. 我已经创建了一个事件EditingControlShowing通过处理PreviewKeyDown但它只能如果在主要一行DataGridView或我是在最后一排主要的dataGridView但如果在MAIN更多然后一排DataGridView然后,如果我按向上“向下箭头”仅在MAIN DataGridView行中移动。

I have tried to control it at DataGridView peviewKey but arrow keys does not register there, also Arrow Keys does not register at DataGridView KeyDown and keypress while in edit mode 我试图在DataGridView peviewKey上对其进行控制,但是箭头键未在其中注册, 箭头键也未在DataGridView KeyDown和在编辑模式下keypress时注册

they are registered at keyup of DataGridView but at this point it do two thing move the rows down or up in both dataGridViews 它们在DataGridView keyup处注册,但是这时它做两件事将两个dataGridViews中的行向下或向上移动

what I want that if MAIN DataGridView cell is in editmode and up or down arrow key are pressed then it only change the row in SUB DataGridView not in main DataGridView 我想要的是,如果MAIN DataGridView单元格处于editmode并按下向上或向下箭头键,那么它只会更改SUB DataGridView的行,而不会更改主DataGridView

Any Ideas! 有任何想法吗!

Have you tried programmatically selecting rows in the sub dataGridView? 您是否尝试以编程方式选择子dataGridView中的行? You can try getting the index of the selected row in the sub grid when the Main PreviewKeyDown event fires and then selecting the next sub dataGridView row like this for example: 您可以尝试在Main PreviewKeyDown事件触发时获取子网格中所选行的索引,然后选择下一个子dataGridView行,例如:

subDataGridView.Rows(index).Selected = False
subDataGridView.Rows(index + 1).Selected = True

or maybe 或者可能

subDataGridView.CurrentCell = DataGridView1.Rows(index + 1).Cells(0);

通过覆盖“ dataGridView”并在此处创建自定义列的解决方案来解决此问题:在此处输入链接描述就像一个魅力一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM