Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringgrid (https://www.delphipraxis.net/110757-ausgewaehlte-zeilen-e-stringgrids-i-e-anderes-stringgrid.html)

aaron 24. Mär 2008 12:29

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Liste der Anhänge anzeigen (Anzahl: 1)
Habe Colcount bei beiden bei 3 und Rowcount bei beiden bei 2.
So sieht der Code gerade aus:
Delphi-Quellcode:
procedure Tform1.Button2Click(Sender: TObject);
var
  i, x2: integer;
begin
for i := 1 to StringGrid1.RowCount -1 do
    for x2 := 1 to StringGrid1.ColCount-1 do
  begin
    if stringgrid1.GetCheckBoxState(0,i,state) then
    begin
    if state = true then
    StringGrid2.Cells[i, x2-1]:=StringGrid1.Cells[i, x2-1];
end;
end;
end;
Freundliche Grüße
Aaron

[EDIT]
schau dir mal bitte das Bild an.
Außerdem ist mir aufgefallen, wenn das zweite stringgrid wieder die gleichen Dimensionen hat bekomme ich beim Ausdruck genau die gleichen Felder angezeigt.
Das will ich ja danach damit machen, habs bislang nicht erwähn weil ich nicht wußte wie es weiter geht.
http://www.delphipraxis.net/internal...200&highlight=

mkinzler 24. Mär 2008 12:36

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Lass mal die Abfrage der Checkboxen weg.

aaron 24. Mär 2008 12:42

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Dann wird immer noch eine Zeile angezeigt.

mkinzler 24. Mär 2008 12:48

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich hab es mal mit normalen StringGrids getestet, funktioniert

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i, x2: integer;
begin
  for i := 1 to StringGrid1.RowCount -1 do
    for x2 := 1 to StringGrid1.ColCount-1 do
    begin
      //if stringgrid1.GetCheckBoxState(0,i,state) then
      begin
        //if state = true then
            StringGrid2.Cells[i, x2]:=StringGrid1.Cells[i, x2];
      end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.rows[0].CommaText := 'Spalte1, Spalte2, Spalte3';
  StringGrid1.rows[1].CommaText := 'blabla, a , b, c';
  StringGrid1.rows[2].CommaText := 'ablabl, 1 , 2, 3';

end;

end.

aaron 24. Mär 2008 12:58

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Liste der Anhänge anzeigen (Anzahl: 1)
Stimmt, das funktioniert.
Ich bau das jetzt auf einer anderern Form mal mit den Checkboxen, bin ja gespannt.
Gruß
Aaron

[Edit]
Mit den Checkboxen funktioniert es wieder nicht.
(Screenshot)

aaron 24. Mär 2008 13:15

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Das mit der Listbox klappt:
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  i: Integer;
  state: boolean;
begin
  Listbox1.Items.Clear;

  for i := 1 to StringGrid1.RowCount - 1 do
  begin
    if stringgrid1.GetCheckBoxState(0,i,state) then
    begin
      if state then
      begin
        StringGrid1.SetCheckBoxState(0,i,false);
   ListBox1.Items.Add(Stringgrid1.Cells[1,i]+Stringgrid1.Cells[2,i]);
        end;
    end;
  end;
  if listbox1.Items.Count = 0 then
    ShowMessage('No items selected');
  StringGrid1.Invalidate;
end;

aaron 24. Mär 2008 13:24

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
So komme ich nun auch ans Ziel, obwohl ich ja gerne gewußt hätte was ich falsch mache:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  state: boolean;
begin
  Listbox1.Items.Clear;

  for i := 1 to StringGrid1.RowCount - 1 do
  begin
    if stringgrid1.GetCheckBoxState(0,i,state) then
    begin
      if state then
      begin
        StringGrid1.SetCheckBoxState(0,i,false);
        ListBox1.Items.Add(Stringgrid1.Cells[1,i]+';'+Stringgrid1.Cells[2,i]);
        ListBox1.Items.SaveToFile(extractfilepath(application.exename)+'data\tmp.txt');
        end;
    end;
  end;
  if listbox1.Items.Count = 0 then
    ShowMessage('No items selected');
   StringGrid1.Invalidate;

  StringGrid2.Clear;
  Form1.StringGrid2.Delimiter := ';';
  StringGrid2.loadfromCSV(extractfilepath(application.exename)+'data\tmp.txt');
end;
Freundliche Grüße
Aaron

mkinzler 24. Mär 2008 13:25

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Ich kenne die TMS-Komponente leider nicht.

aaron 24. Mär 2008 13:51

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Die sind echt gut, erleichtern "manchmal" die Arbeit.
Ich möchte mich für deine Hilfe nochmal bei dir bedanken.
Gruß
Aaron

mkinzler 24. Mär 2008 13:52

Re: Ausgewählte Zeilen e. Stringgrid's i.e. anderes Stringg
 
Ich werde mir mal die Demoversion herunterladen.
Könntest du mir dein Testprojekt mal einstellen?


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:11 Uhr.
Seite 2 von 3     12 3      

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