whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

36 Visitors Online


 
...implement the OnColumnClick Event from TListview for a TStringGrid?
Autor: Miesgram
[ Print tip ]  

Tip Rating (4):  
     


{
 There are two routines to implement the OnColumnClick Methods for a TStringGrid.
 Set the first row as fixed and the Defaultdrawing to True.

 Mit folgenden zwei Routinen kann man in einem TStringgrid
 die Methode OnColumnClick eines TListView erzeugen (visuell).
 Reihe 0 muß fixiert sein undDefaultDrawing = True
}


type
  
TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    
zelle: TRect; // cell
    
acol, arow: Integer;
  public
  end
;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  
Text: string;
begin
  with 
stringgrid1 do
  begin
    
MouseRoCell(x, y, acol, arow);
    if (arow = 0) and (button = mbleft) then
      case 
acol of
        
0..2:
          begin
            
// Draws a 3D Effect (Push)
            // Zeichnet 3D-Effekt (Push)
            
zelle := CellRect(acol, arow);
            Text := Cells[acol, arow];
            Canvas.Font := Font;
            Canvas.Brush.Color := clBtnFace;
            Canvas.FillRect(zelle);
            Canvas.TextRect(zelle, zelle.Left + 2, zelle.Top + 2, Text);
            DrawEdge(Canvas.Handle, zelle, 10, 2 or or 8);
            DrawEdge(Canvas.Handle, zelle, 2 or 4, 1);
          end;
      end;
  end;
end;

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  
Text: string;
begin
  with 
StringGrid1 do
  begin
    
// Draws a 3D-Effect (Up)
    // Zeichnet 3D-Effekt (Up)
    
Text := Cells[acol, arow];
    if arow = 0 then
    begin
      
Canvas.Font := Font;
      Canvas.Brush.Color := clBtnFace;
      Canvas.FillRect(zelle);
      Canvas.TextRect(zelle, zelle.Left + 2, zelle.Top + 2, Text);
      DrawEdge(Canvas.Handle, zelle, 4, 4 or 8);
      DrawEdge(Canvas.Handle, zelle, 4, 1 or 2);
      MouseToCell(zelle.Left, zelle.Top, acol, arow);
    end;
  end;
  if (arow = 0) and (Button = mbleft) then
    case 
acol of
      
0..2:
        begin
          
// Code to be executed...
          // Programmcode der ausgeführt werden soll
          
ShowMessage('Column ' + IntToStr(acol));
          zelle := stringgrid1.CellRect(1, 1);
        end;
    end;
end;

end.

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners