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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid cell focus behavior - Select all characters instead of dropping cursor at a specific character

Status
Not open for further replies.

steve4king

IS-IT--Management
Feb 6, 2007
154
US
I've got a read only grid, there's no reason anyone would want to drop a cursor into the middle, beginning, or end of a value. However, for sorting reasons, I do want to be able to select the cell (specify column/row)

The problem with dropping the cursor into the cell's value, is that I cannot use the arrow keys to move left and right between cells easily.
This seems like a basic grid behavior.. yet I cannot seem to identify it.

Any ideas?
 
In-case someone else has the same question. I didn't find anything that worked well in the grid settings, so I just trapped the keypress event for the form to intercept left and right arrow keypresses.

Code:
Do Case
	CASE nKeyCode = 4
		NODEFAULT
		WITH thisform.grdlookup
	 		.SetFocus
			FOR i = .ActiveColumn + 1 TO .ColumnCount
				IF .columns(i).visible
					.columns(i).setfocus
					EXIT 
				ENDIF 
			ENDFOR 
		ENDWITH
			 	
	CASE nKeyCode = 19
		NODEFAULT 
		WITH thisform.grdlookup
			.SetFocus
			FOR i = .ActiveColumn - 1 TO 1 STEP -1
				IF .columns(i).visible
					.columns(i).setfocus
					EXIT 
				ENDIF 
			ENDFOR 
		ENDWITH
ENDCASE
 
For moving between columns the default key would be TAB and SHIT TAB for reverse tabbing, not arrow keys. Why do you want non standard behaviour?

If you don't want Cell Selection, then you'd even just set AllowCellSelection = .F.
And in regard to column selection there is the grid header, or did you hide that?

You can use GridHitTest in the grid Mousedown event, especially if you set AllowCellSelection = .F. the grid should get these events, while normally the textbox within a column would get it.

Bye, Olaf.
 
Steve,

Why exactly do you want to be able to select the cell "for sorting reasons"?

The usual way to sort a grid would be to click on the column header. You don't need to touch any cells. Just have the user click on the header, and respond by changing the index order of the underlying table. To give feedback to the user, you can show a small icon, such as an up- or down-arrow, as the header's Picture property.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I am not writing errata for all my errors. But this time I have to say it should of course be SHIFT TAB for backtabbing. It would be awfully complicated to swollow keys to be able to excrete TABs when needed.

Bye, Olaf.
 
The default behavior you are getting is the standard Windows behavior. If you change it, your application will work differently than all other Windows applications. My experience is that users expect the grid to behave like Excel, and what you want is different than that.

Craig Berntson
MCSD, Visual C# MVP,
 
This is an update to a pre-existing application, so while I agree with some of these points; a change to require tab or shifttab would not be welcomed by the existing customer base.
Existing users expect to be able to use arrow keys to navigate left right up and down.

Users like the ability to see the row/column/selected cell highlighted for personal reference, whether or not it affects the program behavior. (so AllowCellSelection is required)

Mike, unfortunately the sorting was not designed the best by the original programmer(s). The columns/headers are dynamically constructed, and this process has a quirk or two. As a result, enabling sorting via the column headers wasn't as simple as overriding the header object to replace it's click event. If I had more time on the project, I would have liked to fix those quirks and allow sorting via header click.

The arrow keys are intuitive enough, and I didn't remove the tab/shift-tab functionality. So I think this is the best of both worlds. The arrow keys have no other use in this window.


Thanks for the feedback.
Even if it doesn't lead to action in this case, it's great to be able to see/share your feelings on best practices.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top