geocoins-software
asked on
TDBGrid Title Header Glyphs
I would like to Add the capability of showing a up & down arrow glyph to the column that is currently sorted based on its sort order.
See screenshot for an example from another program i found.
Currently, I change the title caption to bold if its sorted.
See my attached code snipplet
I know how to create glyphs, and I know how to add the glyphs to my current resource file. I just need the code to draw the glyphs on the current sorted columns title header. Because I allow my users to change each columns title header properties (font, background color, ect) - the code should respect the current sorted columns properties.
THanks
See screenshot for an example from another program i found.
Currently, I change the title caption to bold if its sorted.
See my attached code snipplet
I know how to create glyphs, and I know how to add the glyphs to my current resource file. I just need the code to draw the glyphs on the current sorted columns title header. Because I allow my users to change each columns title header properties (font, background color, ect) - the code should respect the current sorted columns properties.
THanks
procedure TfrmMain.grdMainTitleClick(Column: TColumn);
{$J+}
const PreviousColumnIndex : integer = -1;
{$J-}
begin
if grdMain.DataSource.DataSet is TCustomADODataSet then
with TCustomADODataSet(grdMain.DataSource.DataSet) do
begin
try
grdMain.Columns[PreviousColumnIndex].title.Font.Style := grdMain.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
except
end;
Column.title.Font.Style := Column.title.Font.Style + [fsBold];
PreviousColumnIndex := Column.Index;
if (Pos(Column.Field.FieldName, Sort) = 1)
and (Pos(' DESC', Sort)= 0) then
Sort := Column.Field.FieldName + ' DESC'
else
Sort := Column.Field.FieldName + ' ASC';
end;
end;
gsak-screenshot.jpg
oh i forgot to mention, set HeaderControl1.Images to ImageList1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
TheRealLoki:
You can do what i need with a standard TDBGrid.
Mikelittlewood:
Thanks, but i would like to use a TDBGrid
You can do what i need with a standard TDBGrid.
Mikelittlewood:
Thanks, but i would like to use a TDBGrid
good luck getting an image in the standard grid...
in your other related question you said you wanted to use the grid you already had...
guess you changed your mind :-)
guess you changed your mind :-)
However, you can use a THeaderControl instead
it even goes so far as to allow you to do custom drawing of each header section
here's an example I whipped up for you to do the "sort" icons
you will need :-
a TImageList (callled imagelist1) with 2 images in it
place a TPanel on the form (called panel1)
place a THeaderControl (from the Win32 tab) inside panel1
move your dbgrid into panel1 below the header control
turn off the title in your dbgrid
dbgrid1.Options -> untick "rgTitle"
now use the folliowing code, putting the call to your sort routine in place of "Do_SortDataRoutine"
Open in new window