Capturing Control Keys (Arrow Movement) within the DataGrid
Posted on 2004-11-27
I've seen a bunch of examples here on how to capture the KeyPress and KeyDown events within a datagrid to capture arrow movement within a datagrid, but there's been so many varying options, that I am now thouroughly confused. I have a very simple requirement that I have spent hours trying to solve, to no avail. The following is what I have/need:
I have a read only data grid that displays a list of items in 3-5 columns. I am only using the data grid to list items so that when a user clicks a row, another action fires in my application. In other words, no editing, adding or deleting... only clicking and sorting. This works very well with the default datagrid options, but I need two things to happen which I can't seem to control. The first, is that I don't want the user to "enter" a cell. Instead, when they click a cell, the entire row is simply highlighted, and it does not appear as though the user can edit the text in the cell. Even setting the datagrid to read-only doesn't prevent this. The second requirement is that when the user clicks the right or left arrow keys, no action is taken within the datagrid (e.g. cell or row shifting), but a message box appears saying "You clicked the left arrow key" (obviously, there is more to it than this, but this should get me there). Finally, I need the up/down arrow keys to function as they do now and select the previous and next records, but again, just highlighting the row, not entering the individual cell. Can anyone provide me an example of this. I would think it should be easy. Any help is apprecitated!