Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mo 13.11.06 20:31 
Hi Delpher,

ich habe noch nie mit einem ListView gearbeitet. Wie kann ich es mit den Inhalten eines Stringgrids, sagen wir mit 5 Zeilen und drei Spalten, füllen?

Danke für Hilfe,

Detlef A.
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Mo 13.11.06 20:42 
Hi
Guck mal in deiner Delphi Hilfe unter "Items" und "TCustomListView".
Da findest du zwei Beispiele.

MfG
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mo 13.11.06 21:10 
Danke, Coder
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 13.11.06 22:58 
Moin!

Ich hatte hier auch schonmal ein Beispiel gepostet, sogar mit Sortierfunktion. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 14.11.06 13:00 
Danke, Narses,

ich habe jetzt aktuell das Problem, wie ich die Daten aus einem, sagen wir 5 * 3 - Stringgrid in die ListView bekomme - gleiche Reihe und Spalte also. Bei meinen Versuchen werden zwar 5 Spalten angelegt, aber die Items landen alle in der ersten Spalte.

Gruß, Detlef
Jochen W.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 56



BeitragVerfasst: Di 14.11.06 13:05 
user profile iconD. Annies hat folgendes geschrieben:
Bei meinen Versuchen [...]

zeig doch mal deinen Versuch. Dann können wir gezielter helfen. ;-)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 14.11.06 17:38 
Hi, Jochen (et aliter)

hier der Code:

ausblenden 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:
procedure TForm1.FormCreate(Sender: TObject);
var n, k      : integer; 
    ListItem  : TListItem;
    NewColumn : TListColumn;

begin
  with stringgrid1 do
  begin
    cells[0,0] := 'Nr.'; cells[1,0] := 'Datum'; cells[2,0] := 'Name';
    cells[0,1] := '1'; cells[0,2] := '2'; cells[0,3] := '3';
    cells[1,1] := '12.11.2006'; cells[1,2] := '13.11.2006';
    cells[1,3] := '10.11.2006';
    cells[2,1] := 'Annies'; cells[2,2] := 'Detlef';
    cells[2,3] := 'Almut';
  end;
  with ListView1 do
  begin
    for n := 0 to stringgrid1.colcount-1 do
    begin
      NewColumn := Columns.Add;
      NewColumn.Caption := stringgrid1.cells[n,0];
      for k := 1 to stringgrid1.rowcount-1 do
      begin
        ListItem := Items.Add;
        Listitem.Caption := stringgrid1.cells[n,k];
      end;
    end;
  end;
end;


Danke für Antwort, sagt

Detlef A.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Di 14.11.06 18:21 
Du hast ListItem.SubItems vergessen...

War zu Faul mit einer StringGrid zu arbeiten:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
const
  A: Array [0..2, 0..2] of String = (('A', 'B', 'C'), ('1', '2', '3'),
    ('Alpha', 'Beta', 'Gamma'));
var
  I, J: Integer;
  ListColumn: TListColumn;
  ListItem: TListItem;
begin
  for I := 0 to 2 do begin
    ListColumn := ListView1.Columns.Add;
    ListItem := ListView1.Items.Add;
    ListItem.Caption := A[I, 0];
    for J := 1 to 2 do
      ListItem.SubItems.Add(A[I, J]);
  end;
end;
Viele Grüße,
Hape

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 14.11.06 19:15 
Hallo, HansPeter,

ich habe heute wohl ein Brett vor dem Kopf, ich kriege es nicht gebacken !!

Wie sieht denn die Stringgrid-Lösung aus? [Ja, ich weiß, ein Stringgrid ist auch ein Array] - nicht lachen, bitte ...

Danke für Aufklärung, Detlef
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 14.11.06 21:07 
So, ist gelöst, musste aber noch ne Runde rumgugeln ...

Detlef