×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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.

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

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

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

(OP)

Quote (Chris Miller)

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.

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

Quote (Dronner)

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

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

Quote (TamarGranor)

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.

Quote (Dronner)

...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

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

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close