Wolfernox 0 Geschrieben 22. August 2019 Melden Geschrieben 22. August 2019 Hallo möchte den inhalt meiner csv-datei in eine listbox bekommen. Allerding soll in der listbox nur die erste spalte stehen. (also tisch, stuhl und maus. siehe bild) Mein jetziges script: Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() [void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”) [void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”) $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = '1250,500' $Form.text = "Ticket-Mail Generator" $Form.TopMost = $false ####################################################################### # Labels ####################################################################### $User_Lable = New-Object system.Windows.Forms.Label $User_Lable.text = "User:" $User_Lable.AutoSize = $true $User_Lable.width = 25 $User_Lable.height = 10 $User_Lable.location = New-Object System.Drawing.Point(13,26) $User_Lable.Font = 'Microsoft Sans Serif,10' $Betreff_Lable = New-Object system.Windows.Forms.Label $Betreff_Lable.text = "Betreff:" $Betreff_Lable.AutoSize = $true $Betreff_Lable.width = 25 $Betreff_Lable.height = 10 $Betreff_Lable.location = New-Object System.Drawing.Point(13,52) $Betreff_Lable.Font = 'Microsoft Sans Serif,10' $Geschaeftsservice_Lable = New-Object system.Windows.Forms.Label $Geschaeftsservice_Lable.text = "Listbox:" $Geschaeftsservice_Lable.AutoSize = $true $Geschaeftsservice_Lable.width = 25 $Geschaeftsservice_Lable.height = 10 $Geschaeftsservice_Lable.location = New-Object System.Drawing.Point(13,105) $Geschaeftsservice_Lable.Font = 'Microsoft Sans Serif,10' $Inhalt_Lable = New-Object system.Windows.Forms.Label $Inhalt_Lable.text = "Inhalt:" $Inhalt_Lable.AutoSize = $true $Inhalt_Lable.width = 25 $Inhalt_Lable.height = 10 $Inhalt_Lable.location = New-Object System.Drawing.Point(13,145) $Inhalt_Lable.Font = 'Microsoft Sans Serif,10' ####################################################################### # Eingabefelder ####################################################################### $UserBox = New-Object system.Windows.Forms.TextBox $UserBox.width = 150 $UserBox.height = 20 $UserBox.location = New-Object System.Drawing.Point(72,22) $UserBox.Font = 'Microsoft Sans Serif,10' $BetreffBox = New-Object system.Windows.Forms.TextBox $BetreffBox.width = 350 $BetreffBox.height = 20 $BetreffBox.location = New-Object System.Drawing.Point(72,48) $BetreffBox.Font = 'Microsoft Sans Serif,10' $ListBox = New-Object system.Windows.Forms.ComboBox $ListBox.width = 1100 $ListBox.height = 20 $ListBox.location = New-Object System.Drawing.Point(129,101) $ListBox.Font = 'Microsoft Sans Serif,10' $ListBox.Items.Add($data); $Inhalt_txt = New-Object system.Windows.Forms.TextBox $Inhalt_txt.multiline = $true $Inhalt_txt.width = 950 $Inhalt_txt.height = 322 $Inhalt_txt.location = New-Object System.Drawing.Point(72,145) $Inhalt_txt.Font = 'Microsoft Sans Serif,10' ####################################################################### # Standartwert der Eingabefelder ####################################################################### $defaultValue = “” $UserBox.Text = $defaultValue $BetreffBox.Text = $defaultValue $ListBox.Text = $defaultValue $Inhalt_txt.Text = $defaultValue ####################################################################### # CSV-Datei ####################################################################### $data=Import-Csv -Path "C:\listbox.csv" ####################################################################### # Skript-Start ####################################################################### $Form.controls.AddRange(@($ListBox,$UserBox,$BetreffBox,$User_Lable,$Geschaeftsservice_Lable,$Betreff_Lable,$Inhalt_Lable,$Inhalt_txt,$Senden)) [void]$Form.ShowDialog()
daabm 1.428 Geschrieben 22. August 2019 Melden Geschrieben 22. August 2019 Ist das der reale Code? Du fügst $data hinzu, lange bevor es gefüllt wird? Und ich würde der Listbox halt ein eindimensionales Array verfüttern, kein mehrdimensionales (wie es Import-CSV erzeugt). Select-Object dürfte Dir helfen nach dem Import-CSV
Wolfernox 0 Geschrieben 22. August 2019 Autor Melden Geschrieben 22. August 2019 vor 1 Minute schrieb daabm: Ist das der reale Code? Du fügst $data hinzu, lange bevor es gefüllt wird? Und ich würde der Listbox halt ein eindimensionales Array verfüttern, kein mehrdimensionales (wie es Import-CSV erzeugt). Select-Object dürfte Dir helfen nach dem Import-CSV Danke bin noch ein Anfänger was powershell betrifft... könntest du mir sagen wo ich as genau reinschreiben muss?
daabm 1.428 Geschrieben 22. August 2019 Melden Geschrieben 22. August 2019 Für nen Anfänger ist Dein Code aber ziemlich - hm - fortgeschritten... Import-CSV erzeugt ein Array von Arrays - für jede Zeile eines. Wenn die Spalten Header haben, kannst mit "Select-Object" die passende Spalte extrahieren. Und - das wirst Du von andern auch noch hören - hier gibt es keine Lösungen, nur Hilfe zur Selbsthilfe "Was genau wo genau" macht höchstens Olaf ab und zu...
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden