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

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

Status
Not open for further replies.

mstrcmtr

Programmer
Nov 14, 2007
103
PK
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
 
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
 
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:
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
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.


 
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
 
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.
 
FWIW, there's a remembrance of Marcia (by Rick Schummer) in the most recent FoxRockX.

Tamar
 
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
 
You can do that in the header click, but focus must be set to the grid, not to the header, so [tt]This[/tt] is the wrong reference in Header code. As Headers are child objects of grids, it needs to be [tt]This.Parent.SetFocus()[/tt] within the [tt]Header.Click()[/tt] 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:
Bye, Olaf.
 
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:

[tt]This.Parent.Parent.SetFocus()[/tt]

MIke

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top