florisb
asked on
stringgrid code / component
hello there,
I'm using a tstringgrid and I would like to make it look exactly like the one in MS Outlook 2000, I would like the sort functionality (with the visible arrow up / down), and the right mouse pop-up on the upper columns.
I did check Torry's pages and I allready have the components of the 'dreamcompagny'. Has someone experience with a free alternative, that works perfect for this?
Thanx,
Floris.
I'm using a tstringgrid and I would like to make it look exactly like the one in MS Outlook 2000, I would like the sort functionality (with the visible arrow up / down), and the right mouse pop-up on the upper columns.
I did check Torry's pages and I allready have the components of the 'dreamcompagny'. Has someone experience with a free alternative, that works perfect for this?
Thanx,
Floris.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
He thanx! I made my own MouseToCell...(with a + 6 in the proc I posted it did work perfect (upper column is 6 higher than others)).
I used some code I found to made an up and down sort possible by code. I can do the things I want now (sorting goes fast!)
Code here:
procedure TResultaten.GetSort(var GenStrGrid : TStringGrid; ThatCol : Integer;omgekeerdResult : boolean);
{ Description : sort stringlist, by copying to stringlist
(column that has to be sorted is move to beginning line, sort
is done automatically and column is placed back)
Pre : rowcount has to be set correctly!
Post : genstrgrid sorted on Column:ThatCol
Input : -
Returns : -
Creator : Floris
Date : 5-2}
const
TheSeparator = '@'; // Define the Separator
var
CountItem, I, J, K, ThePosition : Integer;
MyList : TStringList;
MyString, TempString : String;
begin
CountItem := GenStrGrid.RowCount; // Give the number of rows in the StringGrid
MyList := TStringList.Create;//Creat e the List
MyList.Sorted := False;
try
begin
for I := 1 to (CountItem - 1) do
begin
MyList.Add(GenStrGrid.Rows [I].String s[ThatCol] + TheSeparator + GenStrGrid.Rows[I].Text);
end;
Mylist.Sort;//Sort the List
for K := 1 to Mylist.Count do
begin
MyString := MyList.Strings[(K - 1)];//Take the String of the line (K – 1)
ThePosition := Pos(TheSeparator, MyString);//Find the position of the Separator in the String
TempString := '';
//element waarop gesorteerd is kan nu verwijderd worden van eerste positie
TempString := Copy(MyString, (ThePosition + 1), Length(MyString));
MyList.Strings[(K - 1)] := '';
MyList.Strings[(K - 1)] := TempString;
end;
if not omgekeerdResult then
begin
for J := 1 to (CountItem - 1) do
GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];//Refill the StringGrid
end
else
begin
for J := 1 to (CountItem - 1) do
GenStrGrid.Rows[J].Text := MyList.Strings[((CountItem -2)-(J - 1))];//Refill the StringGrid
end;
end;
finally
MyList.Free;//Free the List
end;
end;
procedure TResultaten.grdResultConte xtPopup(Se nder: TObject;
MousePos: TPoint; var Handled: Boolean);
var
Col,Row : integer;
begin
end;
procedure TResultaten.grdResultMouse Down(Sende r: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{ Description : right and leftmouse handling, sort if column click.
Pre :
Post :
Input : -
Returns : -
Creator : Floris
Date : 3-2, update 4-2}
var
Col,Row : integer;
begin
//right mouseclick
if Button = mbright then
begin
if activeResultSet = false then //no activerestul, no pop-up at all.
grdResult.popupMenu := nil
else
begin
grdResult.MouseToCell(x,y, Col,Row); //HALELUJA! (wist niet dat deze functie bestond)
If Row = 0 then
grdResult.popupMenu := popupTop //show popup for upper columns
else
begin
grdResult.row := row; //show normal popup and set current row here
grdResult.popupMenu := popupGrid;
end;
end;
end
//left mouseclick
else if (not (activeResultSet = false)) and (ssLeft in Shift) then
begin
grdResult.MouseToCell(x,y, Col,Row); //get row
if row = 0 then
begin
//bepaal of er up of down gesort wordt.
if (col = sortedOnColumn) then
begin
if not omgekeerdResult then //switch after third clicks on same column
omgekeerdResult := true
else
omgekeerdResult := false;
end
else
omgekeerdResult := false;
GetSort(grdResult,col, omgekeerdResult);
grdResult.refresh; //how to refresh that move column line?
sortedOnColumn := col;
// if omgekeerdResult then //na twee maar klikken op zelde kolm; reset
// omgekeerdResult := false;
end;
end;
end;
I used some code I found to made an up and down sort possible by code. I can do the things I want now (sorting goes fast!)
Code here:
procedure TResultaten.GetSort(var GenStrGrid : TStringGrid; ThatCol : Integer;omgekeerdResult : boolean);
{ Description : sort stringlist, by copying to stringlist
(column that has to be sorted is move to beginning line, sort
is done automatically and column is placed back)
Pre : rowcount has to be set correctly!
Post : genstrgrid sorted on Column:ThatCol
Input : -
Returns : -
Creator : Floris
Date : 5-2}
const
TheSeparator = '@'; // Define the Separator
var
CountItem, I, J, K, ThePosition : Integer;
MyList : TStringList;
MyString, TempString : String;
begin
CountItem := GenStrGrid.RowCount; // Give the number of rows in the StringGrid
MyList := TStringList.Create;//Creat
MyList.Sorted := False;
try
begin
for I := 1 to (CountItem - 1) do
begin
MyList.Add(GenStrGrid.Rows
end;
Mylist.Sort;//Sort the List
for K := 1 to Mylist.Count do
begin
MyString := MyList.Strings[(K - 1)];//Take the String of the line (K – 1)
ThePosition := Pos(TheSeparator, MyString);//Find the position of the Separator in the String
TempString := '';
//element waarop gesorteerd is kan nu verwijderd worden van eerste positie
TempString := Copy(MyString, (ThePosition + 1), Length(MyString));
MyList.Strings[(K - 1)] := '';
MyList.Strings[(K - 1)] := TempString;
end;
if not omgekeerdResult then
begin
for J := 1 to (CountItem - 1) do
GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];//Refill the StringGrid
end
else
begin
for J := 1 to (CountItem - 1) do
GenStrGrid.Rows[J].Text := MyList.Strings[((CountItem
end;
end;
finally
MyList.Free;//Free the List
end;
end;
procedure TResultaten.grdResultConte
MousePos: TPoint; var Handled: Boolean);
var
Col,Row : integer;
begin
end;
procedure TResultaten.grdResultMouse
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{ Description : right and leftmouse handling, sort if column click.
Pre :
Post :
Input : -
Returns : -
Creator : Floris
Date : 3-2, update 4-2}
var
Col,Row : integer;
begin
//right mouseclick
if Button = mbright then
begin
if activeResultSet = false then //no activerestul, no pop-up at all.
grdResult.popupMenu := nil
else
begin
grdResult.MouseToCell(x,y,
If Row = 0 then
grdResult.popupMenu := popupTop //show popup for upper columns
else
begin
grdResult.row := row; //show normal popup and set current row here
grdResult.popupMenu := popupGrid;
end;
end;
end
//left mouseclick
else if (not (activeResultSet = false)) and (ssLeft in Shift) then
begin
grdResult.MouseToCell(x,y,
if row = 0 then
begin
//bepaal of er up of down gesort wordt.
if (col = sortedOnColumn) then
begin
if not omgekeerdResult then //switch after third clicks on same column
omgekeerdResult := true
else
omgekeerdResult := false;
end
else
omgekeerdResult := false;
GetSort(grdResult,col, omgekeerdResult);
grdResult.refresh; //how to refresh that move column line?
sortedOnColumn := col;
// if omgekeerdResult then //na twee maar klikken op zelde kolm; reset
// omgekeerdResult := false;
end;
end;
end;
ASKER
thanks for the help meikl, what do you think about the points? Perhaps with another tip from you I can just give them?
Greetings,
Floris.
Greetings,
Floris.
what kind of tip do you need, floris ?
ASKER
Hi Meikl
Maybe tip isn;t the correct English word.
You didn't answer my question, but gave me a good hint... ..errr something to use with tstringgrids? Or some answer on my questoin?
Maybe tip isn;t the correct English word.
You didn't answer my question, but gave me a good hint... ..errr something to use with tstringgrids? Or some answer on my questoin?
ASKER
I do have two more small questions:
After my sort routine, there's a fat black line in the grid (like the one you get if you resize a column), how to I cancel this line?
I would like to have an event when a column is resized, can't find it.
Floris.
After my sort routine, there's a fat black line in the grid (like the one you get if you resize a column), how to I cancel this line?
I would like to have an event when a column is resized, can't find it.
Floris.
ASKER
Okee....;-(
ASKER
No answer to question, but mouseToCell made things much easier...
ASKER
Shitty thing now; two pop-up's like in Outlook, no problemo, making the row active that's right-clicked in; problem:
Should I take the linewidth in account?
I'm really still hoping someone has done all this, I can increase points.
procedure TForm1.grdResultContextPop
var Handled: Boolean);
var
rect : TGridRect;
begin
//right clicked in upper column?
//if grdResult.Selection.
if MousePos.Y <= grdResult.DefaultRowHeight
grdResult.popupMenu := popupTop
else
begin
grdResult.popupMenu := popupGrid;
// showMessage(inttostr(Mouse
if not ( (((MousePos.Y)-1) div grdResult.DefaultRowHeight
grdResult.row := ((MousePos.Y)-1) div grdResult.DefaultRowHeight
end;
end;