• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

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.


0
florisb
Asked:
florisb
  • 7
  • 2
1 Solution
 
florisbAuthor Commented:
Hmmm, trying to use the standard stringgrid now, some problems: points for any solutions I can use:

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.grdResultContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
var
  rect : TGridRect;
begin
//right clicked in upper column?
//if grdResult.Selection.
if MousePos.Y <= grdResult.DefaultRowHeight then
  grdResult.popupMenu := popupTop
else
  begin
  grdResult.popupMenu := popupGrid;
//  showMessage(inttostr(MousePos.Y));
  if not ( (((MousePos.Y)-1) div grdResult.DefaultRowHeight) > grdResult.rowCount-1) then
     grdResult.row := ((MousePos.Y)-1) div grdResult.DefaultRowHeight;
  end;
end;
0
 
kretzschmarCommented:
hi floris,

would this not be easier?

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Row,Col : Integer;
begin
  if Button = mbright then
  Begin
    StringGrid1.MouseToCell(x,y,Col,Row);
    If Row = 0 then
      StringGrid1.popupmenu := popupmenu1  //clicked on title
    else
      StringGrid1.popupmenu := popupmenu2; //clicked in grid
  end;
end;

meikl
0
 
florisbAuthor Commented:
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;//Create the List
  MyList.Sorted := False;
  try
    begin
    for I := 1 to (CountItem - 1) do
      begin
      MyList.Add(GenStrGrid.Rows[I].Strings[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.grdResultContextPopup(Sender: TObject;
  MousePos: TPoint; var Handled: Boolean);
var
  Col,Row : integer;
begin
end;

procedure TResultaten.grdResultMouseDown(Sender: 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;
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
florisbAuthor Commented:
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.
0
 
kretzschmarCommented:
what kind of tip do you need, floris ?
0
 
florisbAuthor Commented:
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?




0
 
florisbAuthor Commented:
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.
0
 
florisbAuthor Commented:
Okee....;-(
0
 
florisbAuthor Commented:
No answer to question, but mouseToCell made things much easier...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now