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.


LVL 2
florisbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.