Autor Beitrag
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Di 17.05.05 07:40 
ich hab bei mir im Programm ne ComboBox, und hatte früher immer mit
ausblenden Delphi-Quelltext
1:
2:
 beginTime := StrToTime(Titem.ItemStartTimeStr);
              cbBeginTime.SelText := TimeToStr(beginTime);

beim laden des Forms mit dieser ComboBox den Wert automatisch selektiert. Zu der Zeit war der Style auf DropDown. Jetzt hab ich allerdings ne Anforderung erhalten, dass der Inhalt der ComboBox nicht Editiert werden darf, bzw. nix selbst rein geschrieben werden darf. Also hab ich den Style auf DropDownList gesetzt es kann nix mehr verändert werden, allerdings wird der Eintrag jetzt nicht mehr selektiert, d.h. das SelText funktioniert nicht mehr. Weiss jemand von euch zufällig ne Lösung zwischen drin??? Also ComboBox nicht editierbar, aber Text selektierbar.
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Di 17.05.05 08:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
      for i := 0 to cbBeginTime.itemindex-1 do
      begin
         if (cbBeginTime.Items[i] = TimeToStr(beginTime)) then
          begin
            cbBeginTime.Text := cbBeginTime.Items[i];
            cbBeginTime.ItemIndex := i;
          end;
      end;

so sollte es gehen, Voraussetzung ist natürlich dass der Eintrag auch wirklich in der Combo existiert.

_________________
mfg. Joel
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 17.05.05 08:44 
Oder so !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
with TStringList.Create do
begin
  AddStrings(cbBeginTime.Items);
  cbBeginTime.ItemIndex := IndexOf(TimeToStr(beginTime));
  Free;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Di 17.05.05 08:51 
So wie im oberen Beispiel funktionert es nicht, da itemIndex am Anfang der For-Schleife nicht die zahl der EInträge ausgibt, sondern den Index des aktuellen.
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Di 17.05.05 08:55 
Problem wurde behoben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  beginTime := StrToTime(Titem.ItemStartTimeStr);
               for i := 0 to cbBeginTime.Items.Count-1 do
               begin
                    if (cbBeginTime.Items[i] = TimeToStr(beginTime)) then
                    begin
                         cbBeginTime.Text := cbBeginTime.Items[i];
                         cbBeginTime.ItemIndex := i;
                    end;
               end;
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Di 17.05.05 09:08 
user profile iconcsigg hat folgendes geschrieben:
Problem wurde behoben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  beginTime := StrToTime(Titem.ItemStartTimeStr);
               for i := 0 to cbBeginTime.Items.Count-1 do
               begin
                    if (cbBeginTime.Items[i] = TimeToStr(beginTime)) then
                    begin
                         cbBeginTime.Text := cbBeginTime.Items[i];
                         cbBeginTime.ItemIndex := i;
                    end;
               end;


upps, logisch, das hatte ich verpeilt ;) Ich hatte den Code aus einem meiner Projekte geklaut, da teste ich aber immer auf DB-Einträge die ich in die Combo lade, deshalb steht da bei mir immer ein while not(eof) do.

_________________
mfg. Joel
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Di 17.05.05 09:19 
Was spricht eigentlich gegen den offensichtlichsten Weg:
ausblenden Delphi-Quelltext
1:
2:
with cbBeginTime do
 ItemIndex := Items.IndexOf(TimeToStr(beginTime));
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Di 17.05.05 09:19 
so funktionierts super, danke.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 17.05.05 09:24 
Sorry,dass ich evtl. Verwirrung gestiftet habe ! Mein Fehler; dachte IndexOf gibt's nur bei TStringList und nicht auch bei TStrings

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Di 17.05.05 09:33 
das einzigste was dagegen spricht ist, dass ich es nicht nochmal ändern will *G*