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

Index by clicking on Header

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi

How to set index with the following code by click on header:

sele phystock
inde on icode tag icode
inde on barcode tag barcode addi
inde on cartons tag cartons addi
inde on units tag units addi
inde on amount tag amount addi

Sele phystock
Go Top
DoDefault()
With Thisform.contMaster.Grid1
.Visible = .T. && Grid control visible
.Themes = .F.
.Width = 925
.Height = 426
.Top = 167
.Left = 0 && Adjust Grid position
.ColumnCount = 6
.HeaderHeight = 29
.RowHeight = 27
.ReadOnly = .T.
.FontName = "Tahoma"
.RecordSource = "Phystock"
.RecordSourceType = 1
.SetAll("dynamicbackcolor", "IIF(RECNO()%2 = 0,RGB(149,221,255), RGB(255,255,255))", "Column")
.DeleteMark = .F.
.ScrollBars = 3
.Column1.Header1.Caption = 'I-Code'
.Column2.Header1.Caption = 'BarCode'
.Column3.Header1.Caption = 'Full Description'
.Column4.Header1.Caption = 'Cartons'
.Column5.Header1.Caption = 'Units'
.Column6.Header1.Caption = 'Value'
.Column1.Header1.Alignment = 2 &&middle right
.Column2.Header1.Alignment = 2 &&middle right
.Column3.Header1.Alignment = 2 &&middle right
.Column4.Header1.Alignment = 2 &&middle right
.Column5.Header1.Alignment = 2 &&middle right
.Column6.Header1.Alignment = 2 &&middle right
.Column1.Alignment = 0
.Column2.Alignment = 0
.Column3.Alignment = 0
.Column4.Alignment = 1
.Column5.Alignment = 1
.Column1.Width = 88
.Column2.Width = 131
.Column3.Width = 340
.Column4.Width = 110
.Column5.Width = 110
.Column6.Width = 110
.Column1.ControlSource = "Phystock.icode"
.Column2.ControlSource = "Phystock.BarCode"
.Column3.ControlSource = "Phystock.Full_desc"
.Column4.ControlSource = "Phystock.Cartons"
.Column5.ControlSource = "Phystock.Units"
.Column6.ControlSource = "Phystock.amount"
.Column1.FontSize = 10
.Column2.FontSize = 10
.Column3.FontSize = 9
.Column4.FontSize = 10
.Column5.FontSize = 10
.Column6.FontSize = 10
.Column4.InputMask = '9,999,999.999'
.Column5.InputMask = '9,999,999.999'
.Column6.InputMask = '99,999,999.99'
Endwith

On single click it should index in ascending order while in dblclick it should be descending.

Thanks

Saif
 
First question - since you have the code there, what is your issue?

Second point...
On single click it should index in ascending order while in dblclick it should be descending.

It is far better to create the cursor and its indexes (all of them) in the Form's Load Method and then use the Header Click/Double Click to Activate the already existing Index - after which you follow with a <whatever>.Grid1.Refresh

Good Luck,
JRB-Bldr
 
Since you create indexes already, you only need to SET ORDER TO TAG tagname in the headers.

Bye, Olaf.
 
On single click it should index in ascending order while in dblclick it should be descending.

That's not the usual way to do it. It's much more common for the first click to sort to ascending, and the second click to sort to descending. That's the way that Outlook does it, for example, and many other programs that have a sortable list of some kind.

To achieve that, you will need to store the current direction (ascending or descending) in a variable or custom property. Then, in the Click event, simply issue a SET ORDER command, with either ASCENDING or DESCENDING, as appropriate.

You definitely should not be creating the indexes every time you click. Create each index once only, as it's needed.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
To make it more intuititive for the user, you can assign an image to .Headern.Picture, a small downarrow image for DESC indexes or a small uparrow image for ASC indexes.

Thus the user can see at a glance which way the records are ordered.

FAQ184-2483​
Chris [pc2]
PDFcommander.co.uk
motrac.co.uk
 
Hi,

Thanks for the reply, I want to say that I am generating the grid through code and there is no physical column header exist so where to put the click event code for ascending/descending, and I am using the same grid1 for Summary and Details means summary grid has 7 columns and Details Grid has 16 columns.

Thanks
 
I want to say that I am generating the grid through code and there is no physical column header exist so where to put the click event code

That needn't be a problem. The way to deal with that is with BINDEVENT(). Read the Help topic for that function, and come back if there's anything you don't understand.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I am using the same grid1 for Summary and Details means summary grid has 7 columns and Details Grid has 16 columns.

I might suggest, for simplicity reasons, that you consider using 2 separate grids on the Form for your 2 separate needs.

You can always make one Visible when the other one is Invisible and vice versa.

Something like:
Code:
ThisForm.Grid1.Enabled = .T.
ThisForm.Grid1.Visible = .T.

ThisForm.Grid2.Enabled = .F.
ThisForm.Grid2.Visible = .F.

And reverse the settings when needed.

The 2 Grids can physically over-lay each other, but only appear when needed.

Good Luck,
JRB-Bldr



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top