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

How do I get the column number of a cell in a foxpro grid Visually?

Status
Not open for further replies.

Dronner

Technical User
Apr 19, 2024
15
0
0
US
Hi Guys,
I'm clear about the procedure to obtain the number of the row that was clicked in a "Visual FoxPro 6" grid, but I don't know how to obtain the column number of this cell where it was clicked by using the Form Designer. The purpose is to locate a specific cell in the grid to execute a procedure depending on the cell that was clicked. Thanks.
 
A column has a control, and that control has events like click or gotfocus to program what you want to program, so there is no need t determine the clumn number, you can directly progam the column controls events.

As there always is more than one way you also get the column number from the grid events Before RowColChange (not applicable in your case) and AfterRowColChange, see parameters f these events. And last not least you have the grid.GridHitTest method, whcih you can use with the mouse coordinates to determine whare tha last click was done. I do mention this last, as it would only be good to use when a cell is activated by a click, it can also be activated with keys, though, like tab/backtab and arrow keys, and then a space causes the click event, too, not only a mouse click. So the straight forward way is to program in the column controls events.

Chriss
 
Chris Miller said:
So the straight forward way is to program in the column controls events.
Honestly, I hadn't thought of it that way and you are right, if I already know the line that was clicked, it is just programming the event in each column.

Thank you so much.
 
Dronner said:
Honestly, I hadn't thought of it that way and you are right, if I already know the line that was clicked, it is just programming the event in each column.

The key is to use something other than the base textbox class. Put the code in the class and use that class in each column and you have what you need.

Tamar
 
TamarGranor said:
The key is to use something other than the base textbox class.

You can also program the text1 textbox that's put into every grid column. As always, there are pros and cons, and the best way is to preprogram a control you then use as grid column control, overriding the default native textbox, that's true.

Still, if you design a form, add a columncount just as many columns as the dbf or cursor you want to display at runtime has, then you can also put code in the textboxes that are created simply by setting a concrete columncount. Just like you can put a native control on a form, double click it and then program into that control on the form.

As you want this to work for every column that's already a case of DRY - dont repeat yourself - and creating a textbox class that reacts to the activation of it, most likely in the gotfocus event, which is exactly the event that always happens, no matter if you activate a control with mouse or tab to it. It gets the focus, and then this event happens, as it got the focus. There's even one that happens before the control gets focus and still the previous control has focus, the When event. So When or Gotfcus are the events you can pick for your concern.

So, indeed I second Tamars advice, create a control class for putting into grid columns.

Dronner said:
...it is just programming the event in each column.
Well, not if you'd literally wanted to program something in the column objects. They don't have any event of activation. It always is the control in the column that gets focus, not the whole column. When using DynamicCurrentControl that cna be one of many controls and always differing depending on which control is picked by the DynamicCurrentControl expression. Usually, though, just one control is the control of a column, repeatedly rendered for each row, there still is only one object, though. and only the current row has that object, so the text1 or however you name the control Tamar suggests you desing as class, will be the control of the active row, when events happen in it, you don't have 10 textboxes when your grid has 10 rows. And in that sense you also don't have to determine which is the rows control, it's only the rows current control, in which events happen, or even just the active cells control. So there is no need to know row or column number, the active cells control has events, you know what it's bound to, so you kjow the field, and you know the row in the dbf or cursor, as it's always just the current row of data.

Chriss
 
Thank you Tamar and Chriss for your contributions, I will keep them in mind.
I've been so busy that I hadn't noticed your posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top