Autor Beitrag
Blamaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 26.06.08 16:50 
Hi,

ich ich lese in meinem Programm Werte in ein ListView.

Wenn ich nun eine Spalte anklicke, wird der Inhalt der kompletten spalte (+ subitems) in Editfelder geladen.

Nun sollen die Werte in den Edits verändert werden können und durch einen klick auf einen Buttons wieder eingetragen werden.

Problem ist momentan folgendes:

Mal Angenommen die ListView enthält gerade folgendes
1 2 3
1. Test1 Test1.1 Test1.2
2. Test2 Test2.1 Test2.2
3. Test3 Test3.1 Test3.2
4. Test4 Test4.1 Test4.2
5. Test5 Test5.1 Test5.2

so ich habe jetzt also auf die Spalte 3 geklickt und somit die Werte Test3 Test3.1 und Test3.2 in die Edits geladen. Nun habe ich den Inhalt der Edits abgeändert und möchte nun erreichen, das der komplette Inhalt der Edits jetzt wieder in die 3. Spalte der Liste eingefügt wird.

Probleme macht mir wie ich also praktisch eine Zeile überschreiben kann.

mfg Blamaster
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 17:15 
Moin!

user profile iconBlamaster hat folgendes geschrieben:
Probleme macht mir wie ich also praktisch eine Zeile überschreiben kann.
Du merkst dir beim Holen der Daten das TListItem, aus dem du die Werte in die Edits kopierst und beim Klick auf den Übernehmen-Button schreibst du auch in das Item wieder rein. :idea: ;)

cu
Narses

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



BeitragVerfasst: Do 26.06.08 17:43 
Thx, so habe ich mir das auch gedacht. Nur wie schreibe ich die Inhalte in einen bestimmten Index Wert ?

mfg Blamaster
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 17:44 
Moin!

user profile iconBlamaster hat folgendes geschrieben:
Nur wie schreibe ich die Inhalte in einen bestimmten Index Wert ?
Zeig mal den Code, mit dem du Items anlegst. ;)

cu
Narses

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



BeitragVerfasst: Do 26.06.08 17:54 
So:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Additem := ListView1.Items.Add;
Additem.SubItems.Add(pchar(Combobox1.Text));
Additem.SubItems.Add(pchar(Combobox2.Text));
Additem.SubItems.Add(Edit2.Text);
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 18:41 
Moin!

Zunächst mal, warum der Typecast auf PChar? :gruebel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Additem := ListView1.Items.Add;
Additem.SubItems.Add(Combobox1.Text);
Additem.SubItems.Add(Combobox2.Text);
Additem.SubItems.Add(Edit2.Text);

Und so das Modifizieren, wenn CurrentItem das TListItem ist, in das die Werte geschrieben werden sollen: :idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
CurrentItem.Caption := 'Titel (Text der 1. Spalte)';
CurrentItem.SubItems.Strings[0] := Combobox1.Text;
CurrentItem.SubItems.Strings[1] := Combobox2.Text;
CurrentItem.SubItems.Strings[2] := Edit2.Text;
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.06.08 18:55 
Hallo,

kannst die Eingaben auch direkt in das selektierte Item zurückschreiben.
ausblenden Delphi-Quelltext
1:
2:
ListView1.Selected.Caption := 'neu';
ListView1.Selected.SubItems[0] := 'auch neu';
vorrausgesetzt das die Selektierung nicht veränderlich ist.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )


Zuletzt bearbeitet von Lannes am Do 26.06.08 19:41, insgesamt 2-mal bearbeitet
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 26.06.08 19:00 
user profile iconNarses hat folgendes geschrieben:

Und so das Modifizieren, wenn CurrentItem das TListItem ist, in das die Werte geschrieben werden sollen


Genau das war ja meine Frage wie kann ich denn CurrentItem nun zuweisen das es das ist wo die Werte reinsollen.

Ich habe jetzt ein Var ID erstellt die den Indexwert enthält und nun ?

mfg Blamaster

@ Lannes

Das geht ja auch nicht wirklich, denn sobald ich im Edit eine eingabe mache, ist ja kein Item mehr Selected ...

Edit.

So läuft das ganze jetzt :)

ausblenden Delphi-Quelltext
1:
ListView1.Items[ID].SubItems[0]:=ComboBox1.Text;					


Zuletzt bearbeitet von Blamaster am Do 26.06.08 19:07, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 19:04 
Moin!

user profile iconBlamaster hat folgendes geschrieben:
Genau das war ja meine Frage wie kann ich denn CurrentItem nun zuweisen das es das ist wo die Werte reinsollen.
Zeig mal den Code vom Buttonhandler, der die Eingabefelder füllt.

cu
Narses

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



BeitragVerfasst: Do 26.06.08 19:07 
Das ganze läuft nun mit

ausblenden Delphi-Quelltext
1:
ListView1.Items[ID].SubItems[0]:=ComboBox1.Text;					


thx @ All

mfg Blamaster
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 19:11 
Moin!

user profile iconBlamaster hat folgendes geschrieben:
Das ganze läuft nun mit

ausblenden Delphi-Quelltext
1:
ListView1.Items[ID].SubItems[0]:=ComboBox1.Text;					
Das mag man zwar so machen können, ich würde mir aber trotzdem lieber eine Referenz auf das betreffende TListItem merken, statt in der ListView rumzusuchen (laut DOH ist das auch nicht grade performant). :nixweiss:

cu
Narses

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



BeitragVerfasst: Do 26.06.08 19:39 
Wieso rumsuchen ?

Wenn ich in der ListView eine Spalte anklicke, wird der Indexwert an die Var ID übergeben.

Wenn ich nun die Liste durch eingaben in die Edits und Combos bearbeite, hat die listview keine selected item mehr und somit auch keinen item index.

Deswegen merkt sich ID den wert.

Wenn ich nun auf den bearbeiten button klicke, tritt halt der obige Code in kraft und es wird sofort auf die Spalte mit dem ID Wert zugegriffen.

Wo wird da also gesucht ?

mfg Blamaster
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.06.08 19:40 
Hallo,

user profile iconBlamaster hat folgendes geschrieben:
@ Lannes
Das geht ja auch nicht wirklich, denn sobald ich im Edit eine eingabe mache, ist ja kein Item mehr Selected ...


setz ListView.HideSelection auf False, dann siehst Du das dass Item selektiert bleibt.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 19:51 
Moin!

user profile iconBlamaster hat folgendes geschrieben:
Wieso rumsuchen ?

Wenn ich in der ListView eine Spalte anklicke, wird der Indexwert an die Var ID übergeben.
Und der Zugriff über den Index wird im TListView über eine Suche abgebildet (AFAIR, oder war´s doch/auch das TTreeView? togal :?).

Vorschlag: :idea:
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:
type
  TForm1 = class(TForm)
    Button1: TButton;
    ListView1: TListView;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
    procedure Button1Click(Sender: TObject);
  private
    FCurrentItem: TListItem;
  public
    { Public-Deklarationen }
  end;

implementation

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
  if Assigned(ListView1.Selected) then begin
    FCurrentItem := ListView1.Selected;
    Edit1.Text := FCurrentItem.Caption;
    Edit2.Text := FCurrentItem.SubItems.Strings[0];
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Assigned(FCurrentItem) then begin
    FCurrentItem.Caption := Edit1.Text;
    FCurrentItem.SubItems.Strings[0] := Edit2.Text;
  end;
end;
cu
Narses

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



BeitragVerfasst: Do 26.06.08 20:17 
Hi,

die Lösung ist natürlich doch etwas sauberer.

Thx :)