Sort When Click On DataWindow Column Title In PowerBuilder. Ex: In Event DataWindow Click Call Function f_dw_sort(This)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | Global Type f_dw_sort From function_object End Type Forward Prototypes Global Subroutine f_dw_sort (datawindow adw) End Prototypes Global Subroutine f_dw_sort (datawindow adw); //==================================================================== // Function: f_dw_sort() //-------------------------------------------------------------------- // Description: Sort When Click On Title Column //-------------------------------------------------------------------- // Arguments: // value datawindow adw //-------------------------------------------------------------------- // Returns: (none) //==================================================================== String ls_col, ls_sort, ls_old Long li_pos Long ll_X1, ll_Y1, ll_X2, ll_Y2, ll_X3, ll_x4, ll_Y3, ll_Y4 String ls_Mod If adw.RowCount() < 1 Then Return adw.SetRedraw( False ) //get old sort ls_old = adw.Object.datawindow.Table.Sort //get column click on ls_col = adw.GetObjectAtPointer() li_pos = Pos(ls_col,'~t') ls_col = Left(ls_col, li_pos - 1) If Not Lower(Right(ls_col,2)) = "_t" Then adw.SetRedraw( True ) Return End If ls_Mod = "Destroy sort_ln1 Destroy sort_ln2 Destroy sort_ln3" adw.Modify( ls_Mod ) ls_col = Left(ls_col, Len(ls_col) - 2) ll_X1 = Long( adw.Describe( ls_col + '_t.X' ) ) + 5 ll_Y1 = Long( adw.Describe( ls_col + '_t.Y' ) ) + 3 ll_X2 = PixelsToUnits( UnitsToPixels( ll_X1, XUnitsToPixels! ) + 4, XPixelsToUnits! ) ll_X3 = PixelsToUnits( UnitsToPixels( ll_X1, XUnitsToPixels! ) + 3, XPixelsToUnits! ) ll_x4 = PixelsToUnits( UnitsToPixels( ll_X1, XUnitsToPixels! ) + 8, XPixelsToUnits! ) ll_Y2 = PixelsToUnits( UnitsToPixels( ll_Y1, YUnitsToPixels! ) + 4, YPixelsToUnits! ) ll_Y3 = PixelsToUnits( UnitsToPixels( ll_Y1, YUnitsToPixels! ) + 5, YPixelsToUnits! ) ll_Y4 = PixelsToUnits( UnitsToPixels( ll_Y1, YUnitsToPixels! ) - 1, YPixelsToUnits! ) ls_sort = ls_col + " A" If ls_sort = ls_old Then ls_sort = ls_col + " D" ls_Mod = 'create line(band=header x1="' + String( ll_X1 ) & + '" y1="' + String( ll_Y2 ) & + '" x2="' + String( ll_x4 ) + '" y2="' + String( ll_Y2 ) & + '" pen.style="0" pen.width="5" ' & + 'pen.color="1089522856" background.mode="2" ' & + 'background.color="16777215" name=sort_ln1 )' ls_Mod += ' create line(band=header x1="' + String( ll_X1 ) & + '" y1="' + String( ll_Y2 ) & + '" x2="' + String( ll_X2 ) + '" y2="' + String( ll_Y1 ) & + '" pen.style="0" pen.width="5" ' & + 'pen.color="33554432" background.mode="2" ' & + 'background.color="16777215" name=sort_ln2 )' ls_Mod += ' create line(band=header x1="' + String( ll_x4 ) & + '" y1="' + String( ll_Y2 ) & + '" x2="' + String( ll_X3 ) + '" y2="' & + String( ll_Y4 ) + '" pen.style="0" pen.width="5" ' & + 'pen.color="1089522856" background.mode="2" ' & + 'background.color="16777215" name=sort_ln3 )' Else ls_sort = ls_col + " A" ls_Mod = 'create line(band=header x1="' + String( ll_X1 ) & + '" y1="' + String( ll_Y1 ) & + '" x2="' + String( ll_x4 ) + '" y2="' & + String( ll_Y1 ) + '" pen.style="0" pen.width="5" ' & + 'pen.color="33554432" background.mode="2" ' & + 'background.color="16777215" name=sort_ln1 )' ls_Mod += ' create line(band=header x1="' + String( ll_X1 ) & + '" y1="' + String( ll_Y1 ) & + '" x2="' + String( ll_X2 ) + '" y2="' & + String( ll_Y2 ) + '" pen.style="0" pen.width="5" ' & + 'pen.color="33554432" background.mode="2" ' & + 'background.color="16777215" name=sort_ln2 )' ls_Mod += ' create line(band=header x1="' + String( ll_x4 ) & + '" y1="' + String( ll_Y1 ) & + '" x2="' + String( ll_X3 ) + '" y2="' & + String( ll_Y3 ) + '" pen.style="0" pen.width="5" ' & + 'pen.color="1089522856" background.mode="2" ' & + 'background.color="16777215" name=sort_ln3 )' End If // Create the triangle adw.Modify( ls_Mod ) adw.SetSort(ls_sort) adw.Sort() adw.SetRedraw( True ) Return End Subroutine |
Good Luck!