Autor Beitrag
Lux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 11:49 
Hallo Leute.
Ich bins mal wieder mit meiner ListView Komponente *wegduck*
Ich hab da mal wieder ein Problem, und hab da eine ganz blöde Frage.
Ich hab halt ne ListView mit vielen Einträgen.
Nun soll das Prog, wenn ich einen Doppelklick auf einen Eintrag mache, ein neues Fenster öffnen, wo ich mit den Gegebenen Werten ein Diagramm machen kann.
Wie ich ein Diagramm zeichne hab ich schon gefunden, wie ich die Werte da eintrage auch.
Allerdings weiß ich noch nicht, wie ich nun dem Programm klar machen kann, auf welches Item ich geklickt habe bei der ListView.

In der Hilfe stand etwas von Selected.
Mit diesem Befehl kann das Prog rausfinden, welches Item Selektiert ist, oder aber ich kann ihm auch sagen, was er selektieren soll.

Allerdings ist mir noch nicht ganz klar wie das gehen soll.
Aus dem Example werde ich auch nicht schlau.

Wenn ich nun aus dem Selektiertem die 1,3 und 5 Spalte haben möchte, wie kann ich das bewerkstelligen?

Vielen Dank für eure Geduld!!

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.03.05 12:05 
Die Eigenschaft Selected des ListViews bezieht sich immer auf die ganze Zeile (wenn vsReport eingestellt ist).

Das mit den Spalten ist so nur realisierbar, wenn es immer die gleichen Spalten sind. Variabel per Mausclick geht das so nicht.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 12:22 
Die Zeile ist so aufgebaut.

Name | Thema | Übung | Adaptiv | Datum | Uhrzeit | Wert | Eregbnis

Und es ist nun nicht möglich aus dem selektiertem Item nun den Namen, die Übung und das Datum raus zu holen?

Hab ich das richtig verstanden?

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.03.05 12:27 
Nein, natürlich geht das. Wenn du die Zeile hast, kannst du doch auch auf die SubItems per Index zugreifen.
Was nicht geht ist, dass du einmal mit der Maus auf Übung clickst, umd die zu bekommen und beim nächsten mal auf Datum, um das zu erhalten. Das wäre so nicht vorgesehen.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 12:34 
Ach soooo!
Jetzt ist es klar :)
allerdings würde ich nun noch gern wissen, wie der Befehl ist...
Listbox1.Selected.keine Ahnung

Kannst du mir das vielleicht auch noch sagen?
Dann wäre ich erstmal glücklich :)

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 12:56 
Ich glaube ich habs raus.

ListView.Selected ist das Item und
ListView.Selected.subItems[2] ist dann das SubItem

Nur muss ich es nun noch ausprobieren ;)

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.03.05 13:00 
So geht es los, Details siehe Delphi-Hilfe zu TListView, TListItem:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button3Click(Sender: TObject);
var
  Item: TListItem;
  Text0: string;
  Text2: string;
  Text4: string;
begin
  if ListView1.Selected <> nil then
  begin
    Item := ListView1.Selected;
    Text0 := Item.Caption;
    Text2 := Item.SubItems[1];
    Text4 := Item.SubItems[3];
  end;
end;
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 16:06 
Vielen Dank nochmal.
Nun hab ich das Problem, dass ich nun noch weitere daten aus der Listview holen möchte um das Diagramm dann vollständig zu machen. Mit einem Wert lässt es sich schwer darstellen ;)

Nun dachte ich mir. Okay lässt halt die Listview durchsuchen und dann das Datum und den Wert schreibste dann weiter in das Diagramm rein. Das sieht dann so aus:

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:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
procedure THauptmenue_frm.ListView1DblClick(Sender: TObject);
var
  YAchse_str, Name, Aufgabe, Datum, Wert : string;
  i, j : Integer;
  s : TLineSeries;
begin
  Name    := ListView1.Selected.Caption;
  Aufgabe := ListView1.Selected.SubItems[1];
  
  // Title of the Chart
  diagramm_frm.Chart1.Title.Text.Clear;
  diagramm_frm.Chart1.Title.Text.Add('Diagramm von ' + Name);

  // Create first Series
  s := TLineSeries.Create(nil);
  // Clear it
  s.Clear;
  // set the title
  s.Title := ListView1.Selected.SubItems[0] + ' - ' + Aufgabe;
  // determine the chart, this series belongs to
  s.ParentChart := diagramm_frm.Chart1;
  // the x-axis shall use date
  s.XValues.DateTime := True;


{Ab hier beginnt die Suche nach den anderen Werten}
  // now add values
  for i := 0 to ListView1.Items.Count - 1 do
  begin
    if ListView1.Items[i].Caption = Name then
    begin
      if ListView1.Selected.SubItems[1] = Aufgabe then
      begin

      YAchse_str := StringReplace(ListView1.Selected.SubItems[5], '.',',', [rfReplaceAll]);
      s.AddXY(StrToDateTime(ListView1.Selected.SubItems[4]), StrtoFloat(YAchse_str));
      end;
    end;
  end;

  diagramm_frm.Show
end;


Das dumme daran ist nur, dass es mit if ListView1.Selected.SubItems[1] = Aufgabe then nichtso ganz klappt, weil ich ja in dem moment die Daten nicht selektiere sondern nur suche.
Was muss ich dafür angeben, so das er auch jedes mal den neuen gesuchten Wert da drin hat?
Dachte erst mit ItemFocused dass das geht, ging aber leider auch nicht :)

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.03.05 16:23 
Ich kann dir da gerade nicht ganz folgen.

Du hast einen Eintrag ausgewählt. Dessen Eigenschaft Selected ist true. Da wir unterstellen, dass nur einer ausgewählt sein darf, findest du den über die Eigenschaft Selected der Liste selbst.

Wenn du nun aus anderen Zeilen Werte brauchst, suchst du offensichtlich nach dem Namen, der in der ersten Spalte steht if ListView1.Items[i].Caption = Name then.
Wenn der Name übereinstimmt, dann vergleichst du if ListView1.Selected.SubItems[1] = Aufgabe then eine Spalte in der ausgewählten Zeile mit Aufgabe, wobei Aufgabe vorher aus diesem Eintrag gesetzt wurde?

Kann es sein, dass du if ListView1.Items[i].SubItem[1] = Aufgabe then meinst?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 16.03.05 16:30 
Jaaaaaa! Genau das meinte ich!!!
Komisch, als ich es erst auch so ausprobiert hatte, da klappte das nicht...
Vielen Dank!

Jetzt sieht das alles schon ein wenig besser aus!

Danke nochmals!

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Do 17.03.05 11:00 
Hallo.
Ich nochmal.
2 Fragen habe ich dann nochmal:

1. Wenn ich nun doppelklicke auf einen eintrag in meiner Liste, dann erstellt er schön sein Diagramm. klappt wunderbest. Allerdings wenn ich das Fenster nun schließe und einen neuen Eintrag öffnen möchte, dann klemmt er es einfach hinter dem andere Diagram. Also er löscht das Alte vorher nicht.
Ich hab man könnte mit Chart1.Clear; einfach das Chart löschen, geht allerdings nicht.. Könnt ihr mir da was sagen?

2. Wenn ich das erste mal ein Diagramm öffne, dann erscheint das erste mal im Diagramm rechts, wo aufgelistet wird, welche Farbe welche Bedeutung hat, zu jedem Wert ein Punkt.
Erst beim zweiten mal erscheint dann, was da eigentlich stehen soll.

Zum besseren Verständnis, hier nochmal der komplette Code + Bilder, Links ist das Bild wenn ich es das erste mal geöfnet habe und rechts wenn ich es das zweite mal geöffnet habe.

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:
33:
34:
35:
36:
37:
38:
procedure THauptmenue_frm.ListView1DblClick(Sender: TObject);
var
  YAchse_str, Name, Aufgabe, Datum, Wert : string;
  i, j : Integer;
  s : TLineSeries;
begin
  Name := ListView1.Selected.Caption;
  Aufgabe := ListView1.Selected.SubItems[1];
  // Title of the Chart
  diagramm_frm.Chart1.Title.Text.Clear;
  diagramm_frm.Chart1.Title.Text.Add('Diagramm der Aufgabe ' + ListView1.Selected.SubItems[0] + ' - ' + Aufgabe);

  // Create first Series
  s := TLineSeries.Create(nil);
  // Clear it
  s.Clear;
  // set the title
  s.Title := Name;
  // determine the chart, this series belongs to
  s.ParentChart := diagramm_frm.Chart1;
  // the x-axis shall use date
  s.XValues.DateTime := True;

  // now add values
  for i := 0 to ListView1.Items.Count - 1 do
  begin
    if ListView1.Items[i].Caption = Name then
    begin
      if ListView1.items[i].SubItems[1] = Aufgabe then
      begin
      YAchse_str := StringReplace(ListView1.items[i].SubItems[5], '.',',', [rfReplaceAll]);
      s.AddXY(StrToDateTime(ListView1.items[i].SubItems[3]), StrtoFloat(YAchse_str));
      end;
    end;
  end;

  diagramm_frm.Show
end;
Einloggen, um Attachments anzusehen!
_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Do 17.03.05 15:06 
Also Problem 1 habe ich selber lösen können.
Das geht über
chart1.RemoveAllSeries;
Das setzt man einfahc ganz am Anfang und schon klappt das mit dem Nachbarn.

Nun habe ich allerdings noch keine Lösung zu Problem 2 gefunden.

in s.Title steht immer der name, so wie es sicht gehört, allerdings anzeigen tut er trotzdm das falsche...

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.