INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

Setting Index direction through Grid Column Header click Like My computer in Windows
2

Setting Index direction through Grid Column Header click Like My computer in Windows

Setting Index direction through Grid Column Header click Like My computer in Windows

(OP)
How can set index direction of table Ascending or Descending through click on Grid column Header and show index direction mark on Grid Column Header

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Presumably you already have an index tag on the relevant field.

You will also need a custom propery of the grid to hold the current direction. Let's call this property lAscending.

When you instantiate the grid, set the table's index order to ascending:

CODE -->

SELECT TheTable
SET ORDER TO TheTag ASCENDING
this.lAscending = .T. 

Then, in the click event of the column's header, set the order accordingly:

CODE -->

SELECT TheTable
lcDirection = IIF(this.lAscending, "ASCENDING", "DESCENDING")
SET ORDER TO TheTag &lcDirection
this.lAscending = NOT this.lAscending 

To visually show the current direction, create two small icons: one to resemble an upward-pointing arrow and one for downward-pointing. Let's call these Up.bmp and Down.bmp respectively. When you instantiate the grid, set the header's picture property to point to Up.bmp. Then, in the header's click event, toggle the picture property. So the whole code for the header's click will look something like this:

CODE -->

SELECT TheTable
lcDirection = IIF(this.lAscending, "ASCENDING", "DESCENDING")
lcPic = IIF(this.lAscending, "up.bmp", "down.bmp")
SET ORDER TO TheTag &lcDirection
this.column1.header1.picture = lcPic
this.lAscending = NOT this.lAscending 

Finally, you will need to set focus to the grid to make the changes visible:

CODE -->

this.SetFocus 

Do not refresh the grid at this point. Setting the focus is sufficient and is faster. Also, if you refresh, you will lose the current highlight.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Tore, I noticed that in your reply, you referred to the late Marcia Akins. Like many people in the VFP community, I didn't know that Marcia had passed away earlier this year. This will come as a surprise and a shock to those of us who knew her.

I found some more information here: https://www.foxite.com/archives/very-sad-news-on-m...#

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Yes, sadly she passed away earlier this year, March 12th.

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Indeed, that's sad news to me, now. As I concentrate Foxpro forum work to here and Microsoft English and German MSDN forums and this got no mention there and here, so far, I missed this at UT and Foxite.

IIRC she was at the MVP Summits of 2007 and 2008, at least at one of them, but actually, her face was familiar from the forums already far before I got the pleasure of meeting many faces in Seattle and Redmond. I am very sure I met Barbara Peisch, Cindy Winegarden, Cathy Pountney, and of course Tamar. I skip mentioning all the men, but it feels a bit weird right now, that I can't say for sure if Marcia also was there.

I have the sad memory of meeting Ken Murphy just a few days before he died, it always is shocking especially with no sign of any serious illness. It's sad this happened so fast, but at least comforting to read she died in no agony. I also say that in comparison with the circumstances of the death of Drew Speedie and his son Brent 2005.

Farewell, Olaf.


RE: Setting Index direction through Grid Column Header click Like My computer in Windows

(OP)
Thanks All

How can all this above table order coding handle if Grid Columns set in a Custom Method e.g.


WITH thisform.Grid1 As Grid

.RecordSource = ''

.RecordSourceType = 1
.RecordSource = 'Tc_Ab'

.FontCharSet = 0
.ReadOnly = .T.

.ColumnCount = 10

Endwith

Now All 10 Columns order setting coding

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

The best general approach to this is defining a header class with the lAscending property and a cIndexTag property to define the index to use, if any.

This leaves the task for a developer to specify index used for sorting a column.

An even more general solution finding the index itself or creating it on the fly is not recommended, as you shouldn't burden tables with an index on each field just for sake of being able to order by index.

There are some hard and soft indexing rules you need to know, for example indexing is impossible on a cursor after buffered changes exist - that's a hard rule. So in case of using views as grid source, every index you need later has to be created right after the query and before you go into any buffering mode. You should create temp indexes for that matter - that's a soft rule following from the other soft rule to not have too many permanent indexes on a table, which only support sorting and no query rushmore optimization. Temp indexes should be done into separate local IDX files, which automatically play no role for the central DBF and are no burden. When creating indexes on query result cursors and view cursors, you can generate tags of the core CDX index file, though, as the overall cursor/view is temporary anyway.

A much more general approach would rebuild a query with corresponding ORDER BY clause and reexecute that. As long as you don't also use the grid for editing, which will add the need to first commit changes before requerying with a changed query.

Bye, Olaf.

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

FWIW, there's a remembrance of Marcia (by Rick Schummer) in the most recent FoxRockX.

Tamar

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

(OP)
where to write the Following Code to Focus Grid after setting index direction in Header Click event

this.SetFocus

If anyone have files for up and down arrow pictures like windows in .bmp or .png format then please sent which are small in size to fit in grid Header Thanks

Which type is better bmp or png or any other

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

You can do that in the header click, but focus must be set to the grid, not to the header, so This is the wrong reference in Header code. As Headers are child objects of grids, it needs to be This.Parent.SetFocus() within the Header.Click() event.

PNG or BMP don't matter, but PNG has the better smooth alpha (transparency) option.

Make a screenshot of dingbats arrow characters, for example. VFP offers some royalty free (to distribute freely) icons and graphics in HOME()+"Graphics", but the style is very outdated. A typical application needs much more icons and you find free sets everywhere, just one example: https://pixabay.com/en/

Bye, Olaf.

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Quote:

As Headers are child objects of grids, it will be This.Parent.SetFocus() within the Header.Click() event.

Olaf, I think you are missing a parent. Headers are child objects of columns; columns are children of grids. So he would need:

This.Parent.Parent.SetFocus()

MIke

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Setting Index direction through Grid Column Header click Like My computer in Windows

Mike, yes, you're right, it's two levels up. I could edit my post now, but that would look odd. The point is the grid has to get focus, not a member object of the grid.

Bye, Olaf.

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!

Resources

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