Autor Beitrag
teamrocket0
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 26.08.08 12:41 
Moin Leuts,

habe ein keines Problem.
Ich möchte in einem Stringgrid ein "X" in eine Zelle eintragen in dem ich mit der Maus auf die jeweilige Zelle klicke.

Ich habe mir das "OnMouseDown" Ereigniss ausgesucht und folgenden Code eingesetzt.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  var colum, row: Integer;
  begin
stringgrid1.MouseToCell(X, Y, colum, row);
stringgrid1.Cells[row, colum]:='X';
end;


Wenn ich jetzt aber auf das StingGrid klicke springen die Xse aber nicht da hin wo die Maus ist. :(


Kennt sich da jemand mit aus!?

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Ne, ist OK...das Problem hat sich...war mein Fehler.
habe colum und row vertauscht.

stringgrid1.Cells[colum, row]:='X';

_________________
To be forgotten is worse than death!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 26.08.08 13:15 
Wie wäre mit einer CheckBox ? Baue die doch ein.

_________________
Gruß
Hansa
teamrocket0 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 26.08.08 13:17 
Kann ich denn einfach so eine Checkbox in ein Stringgrid einsetzen?

Das probier ich mal aus....

Edit: Ne. Haut nicht hin. Die Checkboxen verschieben sich nicht mit dem Stringgrid wenn ich an der Schrolbar drehe. Man müsste die alle mit verschieben....Aber sonst keine schlechte Idee! :-)

_________________
To be forgotten is worse than death!
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 26.08.08 13:34 
Du könntest zum Beispiel TListView mit ViewStyle als vsReport verwenden, dann hast du auch deine StringGrid-Ansicht und kannst über Eigenschaften des ListViews Checkboxen für jeden Eintrag herbeizaubern. Wenn du keine verschiedenen Spalten brauchst, tut es auch TCheckListBox.
teamrocket0 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 26.08.08 13:36 
Ne..ich brauche mehrere Spalten über eine variable Anzahl von Zeilen.

_________________
To be forgotten is worse than death!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 26.08.08 13:41 
Du legst einfach eine Checkbox auf das Stringgrid und denkst, das wars ? :lol: Versuche es so hinzukriegen, das entweder 0 oder 1 im Grid steht. 0 steht hierbei für unchecked und 1 für checked. Das wird dann im OnDrawCell ausgewertet und entsprechend gezeichnet, so das man von der 0/1 gar nichts mitkriegt, sondern nur die Checkbox sieht. In Wirklich keit ist das nämlich gar keine. Du kapito ? :mrgreen: Suche geeignetes Codefragment. Kann aber etwas dauern...

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Ne, da kann man schlecht selber draufkommen. Also ungefähr sowas muss im OnDrawCell stehen :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
          if ACol in CheckBoxCols then begin
            DrawRect:=Rect;
            InflateRect(DrawRect,-1,-1);
            DrawState := ISChecked[StrToInt (sgSender.Cells [ACol,ARow]) = 1];
  // ^ die 0/1, die aus dem DB-Original in sgSender steht beeinflusst, ob die
  // CheckBox gecheckt ist ! D.h. sie wird im OnDrawCell je nach Wert gezeichnet !
            sgSender.Canvas.FillRect(Rect); // hinter Cells liegende 0/1 nicht anz.
            DrawFrameControl(sgSender.Canvas.Handle,DrawRect,DFC_BUTTON,DrawState);
          end


In der Prozedur muss das hier deklariert sein :

ausblenden Delphi-Quelltext
1:
2:
const IsChecked : array[Boolean] of Integer =
      (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);


Der Trick ist jetzt, das DrawState zur Auswertung zu verwenden, welches wiederum aus dem Zellwert 0 oder 1 ermittelt wird. Aber auch ein X liesse sich da verwenden.

_________________
Gruß
Hansa
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 26.08.08 14:02 
Warum so kompliziert? Das Delphi-VCL-TListView kann das doch alles schon!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 26.08.08 14:24 
Was ist da kompliziert ? Die paar Zeilen ? :shock: Außerdem : TStringGrid <> TListView.

_________________
Gruß
Hansa
Klaus Müller
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58
Erhaltene Danke: 1

W2000,XP,W2k2S,W2k3S,S2k7S
Delphi XP
BeitragVerfasst: Sa 14.02.09 13:04 
Warum so kompliziert

Hallo Leute,

Hatte gerade das gleich Problem und habe ein was andern Ansatz genommen.
Ich habe mir ein Procedure erstellt die bei dem Ereignis „OnKeyPress“ und "OnMouseDown"
Reingehängt habe.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Procedure Select_Cell;
Var x_Col,y_Row :Integer;
Begin
  x_Col:=Form1.stringgrid1.Col;
  y_Row:=Form1.stringgrid1.Row;


  If x_Col = 0 Then
  Else Begin
    If Form1.stringgrid1.Cells[x_Col, y_Row]='X'
    Then Form1.stringgrid1.Cells[x_Col, y_Row]:=''
    Else Form1.stringgrid1.Cells[x_Col, y_Row]:='X';
  End;
End;


Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt