AGB  ·  Datenschutz  ·  Impressum  







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

Zellinhalt eines Stringgrid

Ein Thema von H.Bothur · begonnen am 4. Aug 2023 · letzter Beitrag vom 7. Aug 2023
 
H.Bothur

Registriert seit: 25. Jun 2012
Ort: Seevetal & Lagos
252 Beiträge
 
Delphi 11 Alexandria
 
#1

Zellinhalt eines Stringgrid

  Alt 4. Aug 2023, 15:41
Delphi-Version: 5
Moin,

ich habe hier ein kleines Testprogramm - ein Stringgrid mit 5 Reihen und 3 Spalten und einem Button. Und immer wenn ich mit dem Cursur in eine andere Zelle gehe sollte mir die Zeile und Spalte und der Zellinhalt angezeigt werden.

Das klappt auch im ersten Moment mit CirsorDown, nur sobald ich wider CursorUp mache stimmen die angezeigten Daten nicht mehr.

Was stimmt da mit mir nicht ??

Hans

Delphi-Quellcode:
unit TestUnit;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

var
  XPos,
  YPos: Integer;
  ZellInhalt: String;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.Cells[0,0]:='Spalte 1';
  StringGrid1.Cells[1,0]:='Spalte 2';
  StringGrid1.Cells[2,0]:='Spalte 3';

  StringGrid1.Cells[0, 1] := 'Apfel';
  StringGrid1.Cells[1, 1] := 'Birne';
  StringGrid1.Cells[2, 1] := 'Pflaume';

  StringGrid1.Cells[0, 2] := 'Erbse';
  StringGrid1.Cells[1, 2] := 'Wurzeln';
  StringGrid1.Cells[2, 2] := 'Kartoffel';

  StringGrid1.Cells[0, 3] := 'Fleisch';
  StringGrid1.Cells[1, 3] := 'Fisch';
  StringGrid1.Cells[2, 3] := 'Wild';

  StringGrid1.Cells[0, 4] := 'Vorspeise';
  StringGrid1.Cells[1, 4] := 'Hauptspeise';
  StringGrid1.Cells[2, 4] := 'Nachtisch';
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
  YPos := StringGrid1.Row +1; {+1 wegen der FixedRow}
  XPos := StringGrid1.Col;
  ZellInhalt := StringGrid1.Cells[XPos, YPos];
  Button1.Caption := IntToStr(YPos) + ' / ' +IntToStr(XPos) + ' / ' +ZellInhalt;
  Button1.Refresh;
end;

end.
Hans-Georg Bothur
www.hermann-juergensen.de
  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 12:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz