tspse
asked on
Grid/List, Sorting, Component
anyone know a component that
is a "grid" where i can sort on
a click on the "header"
and sort both ways?
it has to be a free component
and it must be "includable" in the
main exe, so there is only the exe
to use.
is a "grid" where i can sort on
a click on the "header"
and sort both ways?
it has to be a free component
and it must be "includable" in the
main exe, so there is only the exe
to use.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use vgLibrary (vgDBGrid), please see following code (my case):-
// Title button onClick event
procedure TfrmMain.DBGrid1TitleBtnCl ick(Sender : TObject; ACol: Integer;
Field: TField);
var
SortString : string;
begin
SortString := MainDM.ADOSp1.Sort;
if ShiftDown and (SortString <> '') then
begin
if Pos(Field.FieldName, SortString)>0 then
begin
if Pos(Field.FieldName+' DESC',SortString) > 0 then
SortString := StringReplace(SortString, Field.FieldName+' DESC',Field.FieldName+' ASC',[rfIgnoreCase])
else
SortString := StringReplace(SortString, Field.FieldName+' ASC',Field.FieldName+' DESC',[rfIgnoreCase]);
end
else
SortString := SortString +', '+Field.FieldName+' ASC';
MainDM.ADOSp1.Sort := SortString;
exit;
end;
if SortString <> '' then
begin
if Pos(Field.FieldName+' ASC',SortString) > 0 then
SortString := Field.FieldName+' DESC'
else if Pos(Field.FieldName+' DESC',SortString) > 0 then
SortString := Field.FieldName+' ASC'
else
SortString := Field.FieldName+' ASC';
end
else
SortString := Field.FieldName+' ASC';
MainDM.ADOSp1.Sort := SortString;
end;
// Drawing title button event
procedure TfrmMain.DBGrid1GetBtnPara ms(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; var SortMarker: TSortMarker;
IsDown: Boolean);
var str : string;
begin
str := MainDM.ADOSp1.Sort;
if AnsiPos(Field.FieldName+' ASC', str) > 0 then
SortMarker := smUp
else if AnsiPos(Field.FieldName+' DESC', str) > 0 then
SortMarker := smDown
else
SortMarker := smNone;
end;
As you can see, you only write code for only 2 events. There are images that already defined in the components.
please come to see it at http://www.vglib.com/link-5.html
// Title button onClick event
procedure TfrmMain.DBGrid1TitleBtnCl
Field: TField);
var
SortString : string;
begin
SortString := MainDM.ADOSp1.Sort;
if ShiftDown and (SortString <> '') then
begin
if Pos(Field.FieldName, SortString)>0 then
begin
if Pos(Field.FieldName+' DESC',SortString) > 0 then
SortString := StringReplace(SortString, Field.FieldName+' DESC',Field.FieldName+' ASC',[rfIgnoreCase])
else
SortString := StringReplace(SortString, Field.FieldName+' ASC',Field.FieldName+' DESC',[rfIgnoreCase]);
end
else
SortString := SortString +', '+Field.FieldName+' ASC';
MainDM.ADOSp1.Sort := SortString;
exit;
end;
if SortString <> '' then
begin
if Pos(Field.FieldName+' ASC',SortString) > 0 then
SortString := Field.FieldName+' DESC'
else if Pos(Field.FieldName+' DESC',SortString) > 0 then
SortString := Field.FieldName+' ASC'
else
SortString := Field.FieldName+' ASC';
end
else
SortString := Field.FieldName+' ASC';
MainDM.ADOSp1.Sort := SortString;
end;
// Drawing title button event
procedure TfrmMain.DBGrid1GetBtnPara
AFont: TFont; var Background: TColor; var SortMarker: TSortMarker;
IsDown: Boolean);
var str : string;
begin
str := MainDM.ADOSp1.Sort;
if AnsiPos(Field.FieldName+' ASC', str) > 0 then
SortMarker := smUp
else if AnsiPos(Field.FieldName+' DESC', str) > 0 then
SortMarker := smDown
else
SortMarker := smNone;
end;
As you can see, you only write code for only 2 events. There are images that already defined in the components.
please come to see it at http://www.vglib.com/link-5.html
ASKER
Ok,
SMDB-Grid: looked ok, but i dit not figure out
how to sort the list after its been filled (didnt have much time, nor did it say in page)
GJL: requires delphi updated to "service pack 2" or what
it is called.
Vg-Lib: costs what i saw.
still not satisfied yet.
SMDB-Grid: looked ok, but i dit not figure out
how to sort the list after its been filled (didnt have much time, nor did it say in page)
GJL: requires delphi updated to "service pack 2" or what
it is called.
Vg-Lib: costs what i saw.
still not satisfied yet.
Hi, tspse
I abviously want to sort a DBGrid not a StringGrid. What Database do you use? and what kind of DataSet do you use to access the Database?
For the SMDBGrid.
You can use the OnTitleClick event to catch the Title click.
1. How I can add the sorted column?
SMDBGrid.DataSource.DataSe t.DisableC ontrols;
{add a new sorted column in list - ascending order}
with SMDBGrid.SortColumns.Add do
begin
FieldName := 'yourFieldName';
SortType := stAscending
end;
{add a new sorted column in list - descending order}
with SMDBGrid.SortColumns.Add do
begin
FieldName := 'yourFieldName';
SortType := stDescending;
end;
SMDBGrid.DataSource.DataSe t.EnableCo ntrols;
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
2. How I can clear the all sorted columns?
SMDBGrid.DataSource.DataSe t.DisableC ontrols;
{clear the all sorted columns}
SMDBGrid.SortColumns.Clear ;
SMDBGrid.DataSource.DataSe t.EnableCo ntrols;
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
3. How I can change a standard TSMDBGrid glyphs (sorted arrows, indicator symbols etc)?
You can run the Image Editor application (or any other resource workshop), open the SMDBGrid.RES file and change the any glyphs.
Also did you try ExDBGrid?
Description says:
Automatic Column Sorting (Fields that have indexes will be sortable by clicking the Column Titles), QueryByForm and SortByForm implementation (For Paradox and dBASE any column names specified in the SortByForm procedure must already be indexed. For SQL-based tables, the specified columns need not be indexed.)
Also the JVCL DBGrid noted that is had the feature you wanted. So if needed why not apply the Delphi Patch?
I abviously want to sort a DBGrid not a StringGrid. What Database do you use? and what kind of DataSet do you use to access the Database?
For the SMDBGrid.
You can use the OnTitleClick event to catch the Title click.
1. How I can add the sorted column?
SMDBGrid.DataSource.DataSe
{add a new sorted column in list - ascending order}
with SMDBGrid.SortColumns.Add do
begin
FieldName := 'yourFieldName';
SortType := stAscending
end;
{add a new sorted column in list - descending order}
with SMDBGrid.SortColumns.Add do
begin
FieldName := 'yourFieldName';
SortType := stDescending;
end;
SMDBGrid.DataSource.DataSe
--------------------------
2. How I can clear the all sorted columns?
SMDBGrid.DataSource.DataSe
{clear the all sorted columns}
SMDBGrid.SortColumns.Clear
SMDBGrid.DataSource.DataSe
--------------------------
3. How I can change a standard TSMDBGrid glyphs (sorted arrows, indicator symbols etc)?
You can run the Image Editor application (or any other resource workshop), open the SMDBGrid.RES file and change the any glyphs.
Also did you try ExDBGrid?
Description says:
Automatic Column Sorting (Fields that have indexes will be sortable by clicking the Column Titles), QueryByForm and SortByForm implementation (For Paradox and dBASE any column names specified in the SortByForm procedure must already be indexed. For SQL-based tables, the specified columns need not be indexed.)
Also the JVCL DBGrid noted that is had the feature you wanted. So if needed why not apply the Delphi Patch?
ASKER
im not using any db because the data comes from a ini-file provided by a third-party site
ASKER
BTecho: when i use your code to sort the
SMDBGrid, my program just crashes..
-------------------------- -
Debugger Exception Notification
-------------------------- -
Project htht.exe raised exception class EAccessViolation with message 'Access violation at address 004ACB8F in module 'htht.exe'. Read of address 00000030'. Process stopped. Use Step or Run to continue.
-------------------------- -
OK Help
-------------------------- -
SMDBGrid, my program just crashes..
--------------------------
Debugger Exception Notification
--------------------------
Project htht.exe raised exception class EAccessViolation with message 'Access violation at address 004ACB8F in module 'htht.exe'. Read of address 00000030'. Process stopped. Use Step or Run to continue.
--------------------------
OK Help
--------------------------
tspse:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
ASKER
Hmm, i had totally forgotten about EE :D
The program went down in the drain about the same time
my computer went the same way :D
So basicly i didnt use any code, sort of.
But i still got help, with probably code
that would done the right thing only if i continued,
so i dont dont what to do now, advise would be good on this matter then
(not the code-stuff)
People shouldnt feel that they help out and then not getting any points.
The program went down in the drain about the same time
my computer went the same way :D
So basicly i didnt use any code, sort of.
But i still got help, with probably code
that would done the right thing only if i continued,
so i dont dont what to do now, advise would be good on this matter then
(not the code-stuff)
People shouldnt feel that they help out and then not getting any points.
Hi!
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp
Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: kretzschmar
Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
...Snehanshu
EE Cleanup Volunteer
P.S.
tspse, looks like you didn't try meikl's suggestion at all.
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp
Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: kretzschmar
Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
...Snehanshu
EE Cleanup Volunteer
P.S.
tspse, looks like you didn't try meikl's suggestion at all.
There are some choices
http://freespace.virgin.net/giles.lindsay/GJL-Software/ExDBGrid.html
http://www.scalabium.com/faq/smdbgrid.htm ->also checkout FAQ
http://jvcl.sourceforge.net/main.htm ->includes the RXLib DBGrid
Or you can do this yourself using the DBGrid's OnTitleClick event, you can easy sort using SQL with a TQuery. If you use a TTable you can set the IndexName , but note: you must add 2 indexes, one for descending and one for ascending sort , for each field you want to sort both ways.