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

How to prevent grid's first cell from getting focus?

Status
Not open for further replies.

DirkVFP

Programmer
Aug 25, 2005
57
NL
Hi all,

The following problem keeps bothering me: whenever a user clicks on a value within my grid, the first cell (1,1) always gets focus, after that the cell which the user clicked will get focus. The debugger confirmed this:
Code:
38308.400, frmbestverd.gridresult.When()
38308.400, frmbestverd.gridresult.MouseDown(1, 0, 458, 276)
38308.400, frmbestverd.gridresult.columnartnaam.text1.When()
38308.400, frmbestverd.gridresult.columnartnaam.text1.GotFocus()
38308.400, frmbestverd.gridresult.columnartnaam.text1.Message()
38308.410, frmbestverd.gridresult.columnartnaam.text1.RangeLow()
38308.410, frmbestverd.gridresult.columnartnaam.text1.RangeHigh()
38308.410, frmbestverd.gridresult.columnartnaam.text1.Valid()
38308.410, frmbestverd.gridresult.columnartnaam.text1.LostFocus()
38308.410, frmbestverd.gridresult.columnbesteld.txtbesteld.When()

This only occurs when the grid is clicked for the first time (is it initialized somehow?) If the grid loses focus and it gains focus afterwards, this behaviour doesn't show.

How can I prevent this behaviour?

Since I'm filling fields outside the grid depending on the selected value, this behaviour makes them fill up twice and I just don't want it :)
 
Fascinating. I tried doing a grid with the first column disabled, and guess what - column2 got focus before the column I clicked on.

Raise it as a bug with MS?

I suppose that leaves the option of putting a "hasTheGridBeenSelected" flag on your form, so that the code that fills grid doesn't bother doing it unless this flag is set:

IF myForm.hasTheGridBeenSelected = .F.
myForm.hasTheGridBeenSelected = .T.
RETURN
ELSE
... fill fields as normal
ENDIF
 
Chris,

Doing some more test I found out that this behaviour occurs whenever the recordsource of the grid is refreshed/changed.
I tried handling the events of the first column (read: putting NODEFAULT in text1.When) but this does not prevent it.

The flag you proposed does not help me however. On my form there is also a treeview control and depending on what node the user clicks, the grid is filled. So it does not matter if the grid has been selected or not, it will be filled anyway.

My solution lies in telling my grid to never focus on the first cell available whenever it is clicked. How I will do that is unclear to me, but I will keep testing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top