|
[wd9]Sorting a table by clicking on a column header |
Débuté par Clive Dickinson, 11 oct. 2005 10:32 - 6 réponses |
| |
| | | |
|
| |
Posté le 11 octobre 2005 - 10:32 |
Hello all, I have a memory table which contains columns for surname and given name. I can use the built-in sort capability to sort on either column by clicking on it. However, what I would like is that when I click on the surname column it sorts in combined surname and given name. I can do this by truning off the builtin column sort and then trapping a mouse click in the surname column, but I would prefer to be able to trap a mouse click on the column header. However, the header does not seem to respond to any mouse clicks. Can anyone help, please? Clive Dickinson |
| |
| |
| | | |
|
| | |
| |
Posté le 11 octobre 2005 - 11:37 |
Make one colum with surname and given name or is that to simple bye
Hello all, I have a memory table which contains columns for surname and given name. I can use the built-in sort capability to sort on either column by clicking on it. However, what I would like is that when I click on the surname column it sorts in combined surname and given name. I can do this by truning off the builtin column sort and then trapping a mouse click in the surname column, but I would prefer to be able to trap a mouse click on the column header. However, the header does not seem to respond to any mouse clicks. Can anyone help, please? Clive Dickinson |
| |
| |
| | | |
|
| | |
| |
Posté le 11 octobre 2005 - 12:43 |
Hi Clive, first, I thought that CurrentColumn should do the job, but I get always -1 with it. The following code with an Event("Handler", Table1..Name, WM_LBUTTONUP) should give you the info you need. PROCEDURE Handler(nMsg is int, wParam is int, lParam is int) I, J are int sColumn is string sColumn2 is string FOR I = 1 TO TableCount("", toColumn) // Go through all columns sColumn = TableEnumColumn("", I) J = TableColumnSubscript("", sColumn, tcpDisplay) // Consider that the user did rearrange the columns sColumn = TableEnumColumn("", J) IF MouseXPos() = {sColumn}..X TO {sColumn}..X + {sColumn}..Width THEN sColumn2 = TableEnumColumn("", J) BREAK END END
IF lParam < 0 THEN Trace("Click on column header = " + sColumn2) ELSE Trace("Click on row " + sColumn2) END
Hello all, I have a memory table which contains columns for surname and given name. I can use the built-in sort capability to sort on either column by clicking on it. However, what I would like is that when I click on the surname column it sorts in combined surname and given name. I can do this by truning off the builtin column sort and then trapping a mouse click in the surname column, but I would prefer to be able to trap a mouse click on the column header. However, the header does not seem to respond to any mouse clicks. Can anyone help, please? Clive Dickinson
http://www.invitec.com |
| |
| |
| | | |
|
| | |
| |
Posté le 11 octobre 2005 - 19:16 |
Hello all, I have a memory table which contains columns for surname and given name. I can use the built-in sort capability to sort on either column by clicking on it. However, what I would like is that when I click on the surname column it sorts in combined surname and given name. I can do this by truning off the builtin column sort and then trapping a mouse click in the surname column, but I would prefer to be able to trap a mouse click on the column header. However, the header does not seem to respond to any mouse clicks. Can anyone help, please? Clive Dickinson I'm always amazed by the readiness of some programmers to jump into APIs and Events and all that low-level stuff. I'm not criticising -- if you're comfortable with this stuff, fine, and it's good that WinDev can access this sort of stuff. However, I've found that you can find solutions for most problems within WinDev itself. Put bluntly, if you're prepared to accept a couple of possible minor restrictions (which most end-users won't be aware of anyway), you can solve this problem with just one line of WinDev code. The 'trick'? Just place an image control over the table header for surname. Under the 'General' tab, leave the 'Image' field blank, under 'Details' make sure that 'This image is a click area' is checked, and under 'Style' choose 'Image_Transparent' just to avoid any borders. In the code section of this image control, all you need put to sort your memory table on both surname and first name is the line: TableSort(TableName,"Surname","Firstname") This technique will also work with file tables - you can change the browsing order of the file in the code section. I said there were some restrictions. If you want to completely follow the usual convention of one click sorting in ascending order, another click sorting in descending order, then you will need to add some extra code but depending how fussy you are, that also can be very simple. Similarly if you want to allow resizing of any columns to the left of the surname column, you'll need a bit of extra code for that. Chris L Melbourne, Oz |
| |
| |
| | | |
|
| | |
| |
Posté le 11 octobre 2005 - 19:27 |
Chris, Raimund, Louis and Jan, Thank you all very much for your suggestions. They are all innovative and seem feasible. I will test each one as soon as I have time (tomorrow morning I think) and let you know which one I choose. It is heartwarming to receive such quick and willing responses and also to see the ingenuity applied to such a simple problem. Regards, Clive |
| |
| |
| | | |
|
| | |
| |
Posté le 12 octobre 2005 - 22:46 |
Hello Chris, overall, I think your approach is more expensive. You have to do this for all your tables, every time you insert a new table or control. With my solution you can use it in a class. You can pass the name of the table to this class and have then a general solution. Best regards Raimund
Hello all, I have a memory table which contains columns for surname and given name. I can use the built-in sort capability to sort on either column by clicking on it. However, what I would like is that when I click on the surname column it sorts in combined surname and given name. I can do this by truning off the builtin column sort and then trapping a mouse click in the surname column, but I would prefer to be able to trap a mouse click on the column header. However, the header does not seem to respond to any mouse clicks. Can anyone help, please? Clive Dickinson I'm always amazed by the readiness of some programmers to jump into APIs and Events and all that low-level stuff. I'm not criticising -- if you're comfortable with this stuff, fine, and it's good that WinDev can access this sort of stuff. However, I've found that you can find solutions for most problems within WinDev itself. Put bluntly, if you're prepared to accept a couple of possible minor restrictions (which most end-users won't be aware of anyway), you can solve this problem with just one line of WinDev code. The 'trick'? Just place an image control over the table header for surname. Under the 'General' tab, leave the 'Image' field blank, under 'Details' make sure that 'This image is a click area' is checked, and under 'Style' choose 'Image_Transparent' just to avoid any borders. In the code section of this image control, all you need put to sort your memory table on both surname and first name is the line: TableSort(TableName,"Surname","Firstname") This technique will also work with file tables - you can change the browsing order of the file in the code section. I said there were some restrictions. If you want to completely follow the usual convention of one click sorting in ascending order, another click sorting in descending order, then you will need to add some extra code but depending how fussy you are, that also can be very simple. Similarly if you want to allow resizing of any columns to the left of the surname column, you'll need a bit of extra code for that. Chris L Melbourne, Oz
http://www.invitec.com |
| |
| |
| | | |
|
| | |
| |
Posté le 13 octobre 2005 - 16:53 |
Hello Chris, overall, I think your approach is more expensive. You have to do this for all your tables, every time you insert a new table or control. With my solution you can use it in a class. You can pass the name of the table to this class and have then a general solution. I can't disagree with you, Raimund. It certainly makes sense to use a general recyclable solution if you can rather than a one-off. I must admit I haven't come to grips with classes in WinDev yet (or more accurately, I've avoided them!) though it seems I should tackle them sometime. A number of people in this Forum obviously use classes to great effect. Cheers Chris L Melbourne, Oz |
| |
| |
| | | |
|
| | | | |
| | |
|