AGB  ·  Datenschutz  ·  Impressum  







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

Checkboxen in Stringgrid

Ein Thema von michael.cohrs · begonnen am 16. Mai 2016 · letzter Beitrag vom 18. Mai 2016
 
HolgerX

Registriert seit: 10. Apr 2006
Ort: Leverkusen
984 Beiträge
 
Delphi 6 Professional
 
#6

AW: Checkboxen in Stringgrid

  Alt 16. Mai 2016, 13:51
Delphi-Quellcode:
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;
OK, dann hier nur noch 'true' und 'false' gegen '1' und '0' tauschen, da dort nur die Zahl drinnen steht und nicht der Text.


oder

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

  function CheckBox(Value: boolean): Cardinal;
  begin
    result:= DFCS_INACTIVE; // no Entry
    if Value then // Checked
      result:= DFCS_BUTTONCHECK or DFCS_CHECKED
    else // not Checked
      result:= DFCS_BUTTONCHECK;
    if not Editing then
    result:= result or DFCS_MONO; // no Editing
  end;
  
var
  b : boolean;
begin
  try
    with TStringGrid(Sender) do
      if (ACol {in CheckBoxCols)} =1) and not (gdFixed in State) then begin
        b := StrToBool(Trim(Cells[ACol, ARow]));
        Canvas.FillRect(Rect);
        InflateRect(Rect, -4, -4);
        DrawFrameControl(Canvas.Handle, Rect,DFC_Button,CheckBox(b));
      end; // if gdFixed in State
  except
  end;
end;
Dann ist es egal, ob '0' und '1' oder 'true' und 'false', da StrToBoll beides konvertieren kann..
  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:00 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