Then click on the grid to give it focus, then press and hold the UP or DOWN arrow key and witness the blue highlight jumping across several rows instead of progressing smoothly.Then press and hold the DOWN key, to see that the blue highlighted current cell progresses smoothly down through the rows. Click on the text box to give it focus (instead of the grid).Then run the program to test again as follows: Return base.ProcessCmdKey(ref msg, keyData) Line below is reached if we didn't handle the key in this method, it tells the form/control to handle it Check not already at the last row in the grid before moving down one row Check not already at the first row in the grid before moving up one rowĭataGridView1.CurrentCell = The movement of the highlight then appears to progress evenly and doesn't jump down in strange batches.Īdd this code to the form: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) This moves the current cell without ever giving actual focus to the DataGridView. Then I override the processCmdKey method on the form to capture the keyboard input and if it detects an arrow key then I programmatically change the current cell in the DataGridView (for example to the next row if the DOWN key was detected in processCmdKey). To do this I make another control on the form (for example a textbox, and give focus to the text Box). The only way I have discovered to make the cursor to move smoothly and rapidly up or down the rows without jumping over batches of rows, has been to not let the DataGridView be focused. I have also tried setting the grid to Virtual mode and ReadOnly and changing just about every setting of the grid, but nothing works. I have tried making the grid and the form DoubleBuffered but no success. The strange behaviour exists even when the DataGridView is read only. Then run the program and press and hold the DOWN arrow key to see how the blue highlight jumps down strangely instead of moving smoothly down from row to row. Add a DataGridViewTextBoxColumn in the designer.Īdd some rows to the DataGridView, and add a little formatting to make enough rows visible for your test, in the FormLoad event: private void Form1_Load(object sender, EventArgs e).Drop a DataGridView control onto the form.Why doesn't it visibly move to each row one at a time in a smooth repeating manner, instead of doing ugly hopping over batches of rows? It doesn't even seem to move an number of rows on each jump it makes (like 10-20 rows on each jump, sometimes the whole page, or even reappearing many rows beyond when the user finally releases the key).įor example if the user wants to move the cursor about half way down the page, by pressing the DOWN arrow key and holding it down, then it is very hard to know when to release the key because the cursor is not moving down in an even progress. This movement looks wrong and makes it hard for the user to judge when to release the key to navigate smoothly over several rows. Here is a GIF image showing the behaviour when pressing and holding the DOWN arrow, then releasing it and pressing and holding the UP arrow. Sometimes it doesn't even seem to move at all until the key is finally released, then the cursor jumps directly to several rows ahead having presumably stored all the key presses. If I press and hold down either the UP or DOWN arrow key when focused on a DataGridView, the cursor (blue highlighted cell) doesn't move evenly down the rows, instead it jumps several rows at a time in batches.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |