Autor Beitrag
Blawen
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 616
Erhaltene Danke: 33

Win XP, Vista, 7
Delphi 5 Prof., BDS 2006 Prof. RAD Studio XE
BeitragVerfasst: Mo 02.10.06 00:22 
Hallo Zusammen

Ich möchte in einem jvDBGrid ein Boolescher Wert eines Feldes mit Hilfe einer dbCheckbox anzeigen und verändern können. Ansatzweise habe ich es lösen können und die Angelegenheit funktioniert vom Grundsatz her.

Allerdings habe ich dabei folgendes Problem/Phänomen
- wenn ich eine Checkbox anklicke wird der entsprechende Zellinhalt verändert (Toggle). (Ausnahme sie unten!)
- Danach wird automatisch wieder der 1. Datensatz markiert
- Den Inhalt des ersten Datensatzes kann ich mittels Maus nicht verändern.
Sobald ich die bereits markierte Zelle anklicke, erscheint der ursprüngliche Tabelleninhalt (z.B. „J“ oder „N“), welchen ich zwar jetzt mit der Tastatur verändern kann, jedoch eben nicht mittels Maus.


Kann mir ev. jemand weiterhelfen oder kann mir ein besseres Vorgehen empfehlen?

Besten Dank im voraus.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
procedure TForm1.FormCreate(Sender: TObject);
begin
  DBCheckBox1.DataSource := DSQ;
  DBCheckBox1.DataField  := 'MITARBEITER';
  DBCheckBox1.Visible    := False;
  DBCheckBox1.Color      := DBGrid1.Color;
  DBCheckBox1.Caption    := '';

  DBCheckBox1.ValueChecked   := 'J';
  DBCheckBox1.ValueUnchecked := 'N';
end;


procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
  sPosNr : String;
  Eintrag : String;

begin
 BEGIN
  if DBCheckBox1.Checked then
    begin
      DBCheckBox1.Caption := DBCheckBox1.ValueChecked;
      Eintrag := 'N'
    end
  else
    begin
      DBCheckBox1.Caption := DBCheckBox1.ValueUnChecked;
      Eintrag := 'J';
    end;

  sPosNr := ZQ_Deb.FieldByName('KONTAKTDATEN_ID').AsString;
  ZQ_Deb.SQL.Clear;
  ZQ_Deb.SQL.Text := 'UpDate KONTAKTDATEN SET MITARBEITER = "'+ Eintrag + '" '+
                     'Where KONTAKTDATEN_ID = "' + sPosNr + '"';
  ZQ_Deb.ExecSQL;
  ZQ_Deb.SQL.Text := 'SELECT * from Kontaktdaten';
  ZQ_Deb.Active := True;
 end;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);

const
  IsChecked : array[Boolean] of Integer =
              (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);

var
  Drawstate : Integer;
  DrawRect: TRect;

begin
  if (Column.Field.FieldName = 'MITARBEITER') then
    begin
      DrawRect:=Rect;
      InflateRect(DrawRect,-1,-1);
      DrawState := ISChecked[Column.Field.AsString= 'J'];
      dbGrid1.Canvas.FillRect(Rect);
      DrawFrameControl(dbGrid1.Canvas.Handle, DrawRect, DFC_BUTTON, DrawState);
    end;
end;
Einloggen, um Attachments anzusehen!
_________________
Es kompilert, wir können ausliefern.
Und es kompiliert wieder - das Update ist fertig - bitte 100 Euro ;-)
Blawen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 616
Erhaltene Danke: 33

Win XP, Vista, 7
Delphi 5 Prof., BDS 2006 Prof. RAD Studio XE
BeitragVerfasst: Mi 04.10.06 17:11 
Mit etwas "externer" Hilfe konnte ich das Problem lösen: forum.dsdt.info/view....php?p=194605#194605

Für alle die meine Lösung interessiert;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
  ZQ_Mahn.Edit;
  ZQ_Mahn.FieldbyName('MAHNEN').AsBoolean:=NOT ZQ_Mahn.FieldbyName('MAHNEN').AsBoolean;
  ZQ_Mahn.Post;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
                                       DataCol: Integer; Column: TColumn; State: TGridDrawState);

begin
  if Column.FieldName = 'Mahnen' then
    if (Column.Field.AsString = 'T') then
      ImageList1.draw(DBGrid1.Canvas , rect.left+2,rect.top+2,1)
    else ImageList1.draw(DBGrid1.Canvas , rect.left+2,rect.top+2,0);
end;

_________________
Es kompilert, wir können ausliefern.
Und es kompiliert wieder - das Update ist fertig - bitte 100 Euro ;-)