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

Hover effect on grid row when mouse is pointed over it? 2

Status
Not open for further replies.

gryff15

Programmer
Sep 21, 2016
47
PH
I just newly learned how to put hover effects on a textbox or a shape using MouseEnter and MouseLeave of the object. I change the bordercolor and backcolor of the object when I hover the mouse pointer over it. I'm thinking about doing the same with a grid where data from a created table cursor are displayed. The grid is bound with the table cursor using recordsource in the Properties so all the contents of the table are displayed on it. If possible, I would like an entire row to have a different color (as highlight) when I move the mouse over the grid. Wherever the mouse is pointed, the row should be higlighted, just like in a series of textboxes. Can somebody help me how to do it? Is it possible? I hope the codes are easy to understand.
On my attachment, the mouse is pointed on the second row (Luffy) so its entire row should have different back color.
 
 http://files.engineering.com/getfile.aspx?folder=7fe32425-1136-4fde-a39d-83169464ed74&file=lufffy.jpg
Interesting question.

Off the top of my head, here is a possible approach:

1. Create a custom property for the form (or the grid?) to hold the relative row number of the row under the mouse.

2. In the grid's MouseMove event, call the grid's GridHitTest method. Use that to store the relative row number in the above custom property.

3. In the Init of the grid, set all the columns' DynamicBackColor property, such that, if the row number in the above property is equal to the current relative row number, the row will have a specified colour, otherwise it will have the default colour.

This is only meant to give you a general idea. I'll leave it to you to fill in the details.

(By the way, welcome to the forum.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you for the response.
Sir I don't understand yet most of your instructions. Please bear with me as I am only new to VFP. I'm using VFP 7.
1. How do we create a custom property? Like double clicking the grid and in the "AddProperty" event part? There's "LPARAMETERS cPropertyName, eNewValue, nVisiblity, cDescription" and I don't know how to manipulate these parameters to store the row number under the mouse.
2. Calling the GridHitTest Method is by typing??:
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.GridHitTest
3. Setting the dynamicBackColor property of all the columns seem a lot of effort clicking each of them. Is there like a shortcut to set their DynamicBackColor? In which event of the grid can I type the code for it?

Thank you also for the warm welcome.
 
Well, given that you are new to VFP, this might quite a big chunk of stuff for you to absorb. Are you sure you want to do this right now? It means having to learn some fairly advanced techniques, merely to make a small cosmetic improvement to your form.

On the other hand, it could be a good training exercise. The techniques are likely to be useful elsewhere eventually (especially creating custom properties). But I can imagine it taking you a little while to understand the details, and you might have higher priorities within your project. (That's not meant as a reflection on your learning ability, of course.)

For now, I'll give you a very quick answer to all of your questions, just to get you started:

1. How do we create a custom property? Like double clicking the grid and in the "AddProperty" event part? There's "LPARAMETERS cPropertyName, eNewValue, nVisiblity, cDescription" and I don't know how to manipulate these parameters to store the row number under the mouse.

No, that's not the correct approach. Instead, read the Help topic, "How to: Add Properties to Classes". But where you see references to "class", take those to mean references to "form". So, for example, you will open the Form Designer, and use the Form menu.

2. Calling the GridHitTest Method is by typing??:
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.GridHitTest

You are headed in the right direction with this one. But you need to pass parameters to GridHitTest. Look at the Help topic for GridHitTest for details. You might also need to read up on "output parameters".

3. Setting the dynamicBackColor property of all the columns seem a lot of effort clicking each of them. Is there like a shortcut to set their DynamicBackColor? In which event of the grid can I type the code for it?

Yes, there is a shortcut. It's called SetAll.

You do this in the Init of the grid. You write code that calls the SetAll method of the grid. The SetAll method will set the DynamicBackColor property for all the columns in the grid. For more about Dynamicxxx properties, see Conditional formatting in a Visual FoxPro grid.

Finally, keep in mind that I have never done what you are trying to achieve, so I cannot be sure that what I have told you is completely correct. If I get time later, I'll try to set it up myself, just to be sure it will work. Also, one of the underlying rules of VFP is that there are always at least three different ways of achieving a given goal. So it's quite possible that someone else here might be able to give you a better answer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Having thought about this some more, I'm not convinced that DynamicBackColor would work in this case, as it only takes effect when the grid is refreshed. Let me give it some more thought.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
This wanted feature is a good example of how hard it sometimes can get to implement something seemingly easy.
There is grid.highlight and several more highlight properties configuring a row highlighting feature, which came rather late, I think only in VFP8/9, so you don't have that in VFP7, unfortunately.
But even that feature does not support highlighting as mouse hovering effect.

There is one feature of VFP I never use, and it also doesn't apply to the grid itself, but in general to the base controls embedded in grid columns, ie textbox, combobox, etc. That feature is SpecialEffect= 2 (Hot tracking). It's the only thing providing an automatic mousover effect.

As the grid only has one row of real control and this is just the active row, the other rows are merely repeated pictures of the other rows with their data, you will only get a mousover event for the active row. Mike already mentioned what you want needs to use the GridHitTest method, there is no other way to see where the mouse hovers over within the grid, if not on the active row.

So due to this nature of the grid drawing, it's hardly doable to influence the looks of any but the active row. When the mouse hovers of a grid row, but not the active row, it merely hovers over a picture of that other row, there is nothing reacting to the mouse over. Mike is on the right track that only DynamicCurrentXYZ properties are enabling to influence the look of all rows, as these properties are considered from VFP while drawing or refreshing the grid, typically you set them at designtime and they use IIF or ICASE with expressions depending on table fields. But there is no way to define something always reflecting the row the mouse hovers over easily.

If you thought this would be a good thing to learn as a beginner experience, you're wrong. I second Mike in recommending to put this aside for later and concentrate on more urgent to do items.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top