Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid keyboard shortcuts 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
Is anyone aware of any documentation that discusses any valid user keyboard shortcuts for a Datagrid control - e.g. for navigation, multiple selection etc?

There is some useful .NET documentation at


but I assume this is .NET Specific and want to find

Thanks in advance
 
MS Documentation? No, not that I'm aware of.

Basically, if TabAction is set to GridNavigation, and the MarqueeStyle allows cell editing, you can use:

1. ENTER
2. The arrows
3. ESC
4. DELETE for deleting a record
4. Tab and Shift/Tab
5. Ctrl-End or Ctrl-Home
6. MouseClick on recordselector or Ctrl-MouseClick on recordselector to mark multiple records.

Eveything else can be done in code:
-Blocks or selected records with Shift and Mourse click.
-Move Last/First record
-Move last/first cell/row in grid
-Copy/Cut/Paste records or blocks of records

etc.


 
Thanks CCLINT. I am already using quite a bit of my own code to handle shortcuts but am starting to get a bit confused over what its natural behaviour should be - hence my question to determine the basics.

I am finding that, when using the mouse to select a record, SelbookMarks.Count is set to zero (clearing the last record) by the time it reaches the recordset's WillMove event then it reverts back to 1 when the new record has been selected. However, if I use the arrows to move from one record to another, the original record remains selected and SelBookMarks.Count increases to 2. I would have expected the arrows to behave as per mouse clicks unless, for example, the SHIFT key was used at the same time.

Any thoughts?
 
DBGrid or DataGrid?
What is the property: MarqueeStyle set at?
 
CCLINT - It's a DataGrid.

MarqueeStyle is set to dbgNoMarquee but would this have any bearing on SelBookMarks.Count? I remember getting more than a little confused by this property some considerable time ago and I got some very unpredictable behaviour. Setting to dbgNoMarquee gave fewest problems and rows are still highlighted when set to this value.
 
You have two conditions:

One is the selected records, and the other is the current record.

When you move to a different row in the grid, the recordset moves along with it and fires the Move Events.

However, when you bookmark rows in the grid, only if the first record getting bookmarked is a different record the the current record, will the Move event fire. For all other additions to the bookmark collection, even though you are clicking on other recordselectors while holding down the ctrl key, the currect selected record doesn't change.

Let's say record #5 is the current record (I click in a cell in that row).
Now I click with the mouse on the left hand side of the grid (on the recordselector) on record number 10 while holding the Ctrl key.
The current record is #5, thge same current record as the underlying recordset shows:

rsADO.Fields(0).Value
or
Adodc1.Recorset.Fields(0).Value

The bookmark count is at 1.
Continuing with selecting records, I hold the Ctrl down a second time and select record # 15.
Now I have 2 items in the SelBookmarks collection, the same two rows marked on the grid, but the currecnt record is still record #5 AND not included in the bookmark collection.
Now I select a 3rd row to add to the collection, by Ctrl-mouseclick and this time I selected record #5.
Now record #5, the current record all along, was added.
The whole time I selected the 4 records, the MoveComplete event didn't move, except for the very first time I click in a cell in that record, or mouse clicked the record and therefore selected it with-out holding the Ctrl Key.

Now, as soon as use click on a record with-out holding the Ctrl key, or use an arrow up/down, the bookmark collection gets reset to 0. It would the automatically go to 1, if you clicked on the recordselectore instaead of inside a cell.
With the arrows Up/Down, you aren't selecting records. This is like clicking inside record #5 in column #2 and then clicking in the same column but on record #6.

For the Ctrl-arrow to work like Ctrl-Mouseclick, you need to capture the Ctrl key and the Arrow in the KeyDown event, and then add the bookmark of the current row to the bookmark collection as well. The only thing it doesn't do is prevent the current record from changing. But this you can also correct in code.

I think some of your code is getting things twisted around if the bookmark collection still has items and/or getting items added when you are only using the Up/Down arrors.

>I would have expected the arrows to behave as per mouse clicks unless, for example, the SHIFT key was used at the same time.

They should and they do. The only difference is you need to click on the recordselector to identify that you want to mark a record and add it to the bkmk collection.
This you cannot do with the arrows buttons because with the arrows buttons you cannot move into the RecordSelector area. Again, you would need to capture the CTRL in the KeyDown events.
 
Thanks for taking the time to give such a detailed reply CCLINT. I think your theory that some of my code "is getting things twisted" is very probably correct. However, I have implemented a solution that seems to be working whereby I now trap SHIFT and up/down arrows to allow multi-select but with no SHIFT, they just move the current record.

I understand most of the points you have made but, when I first coded my grid manipulation (some considerable time ago), I don't think I did! I am sure my code could be a lot simpler and a major re-working is probably in order, probably after fully digesting your own comments.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top