Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#27

AW: StringGrid Zeile einfärben

  Alt 13. Jan 2015, 13:42
Also es es wäre zuckersüß, wenn man Delphi-Sourcecode auch in die dafür vorgesehenen Delphi-Tags packen könnte:
Code:
[DELPHI]
procedure foo;
begin
  // do something
end;
[/DELPHI]
Dann sieht das so aus:
Delphi-Quellcode:
procedure foo;
begin
  // do something
end;
Toll, gell?

So jetzt mal zum Thema (ähm, welchem eigentlich):
Delphi-Quellcode:
unit Form.Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;

type
  TForm1 = class( TForm )
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell( Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean );
  private
    function CanSelectCell( ACol, ARow: Integer ): Boolean;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.CanSelectCell( ACol, ARow: Integer ): Boolean;
begin
  Result := not(
    {} ( ( ComboBox1.ItemIndex = 1 ) and ( ACol >= 0 ) and ( ACol <= 2 ) ) or
    {}( ( ComboBox2.ItemIndex = 1 ) and ( ARow >= 1 ) and ( ARow <= 3 ) ) );
end;

procedure TForm1.StringGrid1SelectCell( Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean );
begin
  CanSelect := CanSelectCell( ACol, ARow );
end;

end.
Die Werte muss man eventuell noch anpassen, denn die Zeilen und Spalten sind 0 basiert, heisst also die erste Spalte ist die Spalte 0, analog mit der Zeile.
Und bei der ComboBox sieht es genauso aus, der erste Eintrag hat den ItemIndex 0.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat