Hello guys I'm currently coding an IHM in powershell to configure switches. I'm using a combobox to select a model. The combobx is generated using a dataview generated by a datasource, and the datasource is generated from a csv file by a foreach.
My problem is the following : I can only recover a single column.
Combobox:
$list1 = New-Object System.Windows.Forms.Combobox
$list1.Location = New-Object Drawing.Point 9,45
$list1.Size = New-Object System.Drawing.Size(250,30)
$list1.DropDownStyle = "DropDownList"
$list1.BindingContext = New-Object System.Windows.Forms.BindingContext
$list1.DataSource = $vu1
$list1.ValueMember = "Model"
$list1.DisplayMember = "Model"
$list1.SelectedValue = ""
$mainfrm.controls.add($list1)
Reading infos
Write-Host "$list1.SelectedValue"
Edit foreach and creation of the dataview
foreach:
$ImportData = import-csv "E:\PS\A faire\equipement.csv" -Delimiter ';' | Select Model,Type,Port,Firmware,Comware
$table1 = New-Object system.Data.DataTable
$colonne1 = New-Object system.Data.DataColumn Model,([string])
$table1.columns.add($colonne1)
$colonne2 = New-Object system.Data.DataColumn Port,([string])
$table1.columns.add($colonne2)
$colonne3 = New-Object system.Data.DataColumn Comware,([string])
$table1.columns.add($colonne3)
$colonne4 = New-Object system.Data.DataColumn Firmware,([string])
$table1.columns.add($colonne4)
foreach ($data in $ImportData)
{
$model = $data.Model
$type = $data.Type
$port = $data.Port
$firmware = $data.Firmware
$comware= $data.Comware
$ligne1 = $table1.NewRow()
$ligne1.Model = "$model "+"$type"
$ligne1.Port = "$port"
$ligne1.Comware = "$comware"
$ligne1.Firmware = "$firmware"
$table1.Rows.Add($ligne1)
}
Dataview
$vu1 = New-Object System.Data.DataView($table1)
Instead of using 4 colums in the datasource I put everything in one and then a split. Code after :
$ligne1.Model = "$model "+"$type " + "$port " + "$comware " + "$firmware "
Then you can use a split() to have a usable value.