Autor Beitrag
ChrisHa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 30

Win 7 x64
VS 2010, 2008
BeitragVerfasst: Do 10.04.14 16:36 
Hallo liebe Gemeinde,

bin gerade wirklich am verzweifeln.

ausblenden C#-Quelltext
1:
lst_MovieDatabase.Items.AddRange(MovieProperties.LstName);					


Zum Code:
lst_MovieDatabase - Listbox auf der Form
MovieProperties - Klasse in der das Array vorhanden ist
LstName - List<string> in der Klasse MovieProperties


Fehlermeldungen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
Fehler  
1  Die beste Übereinstimmung für die überladene System.Windows.Forms.ListBox.ObjectCollection.AddRange(System.Windows.Forms.ListBox.ObjectCollection)-Methode hat einige ungültige Argumente.  PFAD  36  13  Movie

UND

Fehler  2  1-Argument: kann nicht von "System.Collections.Generic.List<string>" in "System.Windows.Forms.ListBox.ObjectCollection" konvertiert werden PFAD  36  46  Movie

Es ist sichelrich wieder extrem leicht doch leider finde ich den Fehler einfach nicht. Google sagt mir, dass ich genau das so machen soll.

Vielen Dank für eure Hilfe.

Moderiert von user profile iconTh69: Quote- durch C#-Tags ersetzt
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 10.04.14 16:42 
Die AddRange-Methode nimmt entweder ein Array object[] oder ObjectCollection. List<string> ist in keines davon einfach so konvertierbar. Was aber konvertierbar ist, ist ein string[]-Array, und das bekommst Du so:
ausblenden C#-Quelltext
1:
lst_MovieDatabase.Items.AddRange(MovieProperties.LstName.ToArray());					

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: ChrisHa
ChrisHa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 30

Win 7 x64
VS 2010, 2008
BeitragVerfasst: Do 10.04.14 16:44 
Erstmal danke für die schnelle Antwort.
Jetzt stehen bei mir aber in der List alle Objekte in einer Zeile. Wird wohl am einlesen liegen oder?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 10.04.14 16:48 
Dann wird vorher die List<string> auch nur einen Eintrag gehabt haben und ja, das liegt dann wohl am Einlesen.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: ChrisHa
ChrisHa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 30

Win 7 x64
VS 2010, 2008
BeitragVerfasst: Fr 11.04.14 07:39 
Habe meinen Fehler gefunden.
Tatsächlich beim Einlesen.
ausblenden C#-Quelltext
1:
2:
3:
4:
while (!sr.EndOfStream)
{
    LstName.Add(sr.ReadLine());
}

Hatte hier sr.ReadToEnd(), was natürlich nicht gerade sinnvoll ist.

Es funktioniert jetzt. Danke nochmal an Christian S.

Moderiert von user profile iconChristian S.: Quote- durch C#-Tags ersetzt