AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

StringGrid-Komponente mit Checkbox

Ein Thema von BillieJoe90 · begonnen am 2. Apr 2007 · letzter Beitrag vom 12. Apr 2017
 
Hobby-Programmierer

Registriert seit: 19. Jan 2006
Ort: München
392 Beiträge
 
Delphi XE Starter
 
#9

Re: StringGrid-Komponente mit Checkbox

  Alt 4. Apr 2007, 09:00
Moin ...,
@Schädel & Hansa: genialer Vorschlag von euch
Ich habe ein wenig herumgespielt und herausgekommen ist dies:
Delphi-Quellcode:
var
  Form1: TForm1;
  Editing: Boolean;

Const CheckBoxCols = [1,2]; // Spalte 2 ohne Einträge

implementation
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:= 1 to StringGrid1.RowCount do begin
    StringGrid1.Cells[0,i]:= 'Zeile '+ IntToStr(i);
    StringGrid1.Cells[1,i]:= 'true';
  end;
  Editing:= true; // False = nur Anzeige, true = EditModus
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

  function CheckBox(Value: String): Cardinal;
  begin
    result:= DFCS_INACTIVE; // no Entry
    if Value = 'truethen // Checked
      result:= DFCS_BUTTONCHECK or DFCS_CHECKED
     else if Value = 'falsethen // not Checked
      result:= DFCS_BUTTONCHECK;
    if not Editing then
      result:= result or DFCS_MONO; // no Editing
  end;

begin
  with TStringGrid(Sender) do
    if (ACol in CheckBoxCols) and not (gdFixed in State) then begin
      Canvas.FillRect(Rect);
      InflateRect(Rect, -4, -4);
      DrawFrameControl(Canvas.Handle, Rect,DFC_Button,
                       CheckBox(Trim(Cells[ACol, ARow])));
    end; // if gdFixed in State
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var iCol, iRow: Integer;
begin
  with TStringGrid(Sender) do
    if (Button = mbLeft) and Editing then begin
      MouseToCell(x, y, iCol, iRow);
      if (iCol > 0) and (iRow > 0) then begin
        if Cells[iCol, iRow] = 'truethen // Checked
          Cells[iCol, iRow]:= 'false'
         else if Cells[iCol, iRow] = 'falsethen // not Checked
          Cells[iCol, iRow]:= 'true';
      end;
    end;
end;
LG Mario
Angehängte Dateien
Dateityp: zip stringgrid_mit_checkbox_117.zip (1,8 KB, 142x aufgerufen)
Mario
'Lesen Sie schnell, denn nichts ist beständiger als der Wandel im Internet!'
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:13 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz