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

Grid Navigation 2

Status
Not open for further replies.

tkee

Programmer
Feb 6, 2004
55
US
I have a grid on a form which contains fields from a single cursor. The users are used to vertical textboxes where the navigation would basically go down a column. Now the navigation stays on the same row (when pressing ENTER), moving horizontally. Is there a simple way to change this, or is it just a training issue, i.e., using the down arrow key with set confirm on?
 
Hi tkee,

it is possible, to navigate to a certain column in a certain row programmatically (have a look at 'ActivateCell'), but....as soon as your grids properties allow to move or hide columns at runtime, programmatic navigation isn't fun anymore.

To be honest, when grids where introduced in VFP in the mid 90s I jumped at them with a vengeance for using them for data input. Nowadays, they do nothing but visualize data and select data in my apps. This gives me way more freedom in using containers and multiline rows and on row selection, another part of the form shows a regular data entry that is bound to the same cursor as the grid.

JM2C

-Tom
 
Are they perhaps used to EDIT windows? You can also turn a grid to that vertical orientation by setting GRID.VIEW = 1. It's not the best overview, if you ask me. But it's also what you get by EDIT or CHANGE command. Als, the FREEZE feature isn't available anymore, if you'd like to have a single column editable, but you can make columns unselectable by putting RETURN .F. into their WHEN event.

Chriss
 
Mike Y has given you a good solution. However, in general I prefer to avoid using ON KEY LABEL, because it is a global setting that will affect the entire application rather than just the grid.

The alternative is to use the KeyPress events of the individual textboxes (within the columns). So, in the KeyPress of Grid.Column1.Text1, you would do this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode = 13
  NODEFAULT 
  KEYBOARD '{DNARROW}'
ENDIF

You would then do the same thing in the KeyPresses of the textboxes within all the columns.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

In addition to what Mike Lewis suggested you may want to create your own TextBox subclass with the wanted behavior(s) (see code below) and add them to your grid

Code:
**************************************************
PUBLIC goForm

goForm = NEWOBJECT("frmForm")
goForm.Visible = .T.
goForm.Show

Read Events
Close all
Clear All
RETURN


**************************************************
DEFINE CLASS txtEnterBox as TextBox
	BackColor = RGB(75, 255, 255)
	FontBold = .T.
	
	PROCEDURE KeyPress()
		LPARAMETERS nKeyCode, nShiftAltCtrl

		IF nKeyCode = 13
			NODEFAULT 
			KEYBOARD '{DNARROW}'
		ENDIF
	ENDPROC 
ENDDEFINE

DEFINE CLASS frmForm AS Form
	AutoCenter = .T.
	Caption = "Cities"
	ShowTips = .T.
	Height = 360
	Width = 648
	MinHeight = This.Height
	MinWidth = This.Width

	
	ADD OBJECT grdCities AS Grid WITH ;
		BackColor = RGB(125, 255, 255), ;
		DeleteMark = .F., ;
		Left = 12, ;
		Top = 12, ;
		Width = 648 - 24, ;
		Height = 360 - 24, ;
		RowHeight = 24, ;
		AllowRowSizing = .F., ;
		Anchor = 15, ;
		Themes = .F., ;
		Visible = .T., ;
		ColumnCount = -1, ;
		RecordSource = "curCities"
		
		PROCEDURE grdCities.Init()
			WITH This.Column1
				.Header1.Caption = "City"
				.Header1.FontBold = .T.
				.Width = 120
				.Resizable = .F.
				.NewObject("txtCity","txtEnterBox")
				.CurrentControl = "txtCity"
				.txtCity.Visible = .T.
				.Sparse = .F.
			ENDWITH 

			With This.Column2
				.Header1.Caption = "Country"
				.Header1.FontBold = .T.
				.Width = 60
				.Resizable = .F.
				.NewObject("txtCountry","txtEnterBox")
				.CurrentControl = "txtCountry"
				.txtCountry.Visible = .T.
				.Sparse = .F.
			ENDWITH    	
		ENDPROC 

	PROCEDURE Load()
		CREATE CURSOR curCities (cCity C(25), cCountry C(2))

		INSERT INTO curCities VALUES ("New York", "US")
		INSERT INTO curCities VALUES ("Moscow", "RU")
		INSERT INTO curCities VALUES ("Paris", "FR")
		INSERT INTO curCities VALUES ("Berlin", "GE")
		INSERT INTO curCities VALUES ("London", "GB")
		INSERT INTO curCities VALUES ("Den Haag", "NL")
		
		LOCATE 
	ENDPROC 
	
	PROCEDURE Destroy
		CLOSE ALL
		Clear Events
	ENDPROC

ENDDEFINE

*********************************************

hth

marK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top