I have a GUI with combobox and textbox. I need to update the output of textbox consider to combobox selected file.
I tried this. But the output in the textbox is not correct. Anyone can help please. THank you
$Disk = New-Object system.Windows.Forms.ComboBox
$Disk.AutoSize = $true
$Disk.DropDownStyle = "DropDownList"
$Disk.Items.AddRange((get-partition|?{$_.DriveLetter}|select DiskNumber ))
$SelectedFile= {
$DiskSelected = $Disk.SelectedItem
Write-Host "Disk Selected: $DiskSelected"
$DiskNum = $DiskSelected -split "@{DiskNumber="
$DiskNumber = $DiskNum -split "}"
Write-Host "Disk Number: $DiskNumber"
$TextBox1.AppendText((Get-Disk -Number $DiskNumber))
}
$Disk.add_SelectedIndexChanged($SelectedFile)
$Disk.DisplayMember = 'Name'
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $true
$TextBox1.BackColor = "#F5F5F5"
The output in the textbox is like this
MSFT_Disk (ObjectId = "{1}\\SSXX\root/Microsoft/Windows/Stor...) MSFT_Disk (ObjectId = "{1}\\SSXX\root/Microsoft/Windows/Stor...)
Updated
Now, I can bring the disk information to textbox, but can the textbox does not updated if I select another item in the combobox.
$Disk = New-Object system.Windows.Forms.ComboBox
$Disk.AutoSize = $true
$Disk.DropDownStyle = "DropDownList"
$Disk.Items.AddRange((get-partition|?{$_.DriveLetter}| select DiskNumber ))
$SelectedFile = {
$DiskSelected = $Disk.SelectedItem
Write-Host "Disk Selected: $DiskSelected"
$DiskNum = $DiskSelected -split "@{DiskNumber="
$DiskNumber = $DiskNum -split "}"
Write-Host "Disk Number:$DiskNumber"
Get-Disk | Where-Object -FilterScript {$_.Number -Eq "$DiskNumber"} | Select FriendlyName, BusType, Size | Export-Csv 'Temp.csv' -NoType
$TextBox1.AppendText((Get-Content -Path ".\Temp.csv"))
}
$Disk.add_SelectedIndexChanged($SelectedFile)
$Disk.DisplayMember = 'Name'
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $true
$TextBox1.WordWrap = $true
$TextBox1.BackColor = "#F5F5F5"
$textsize = ($width / 130)
$FontText = New-Object System.Drawing.Font("Calibri",$textsize,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Pixel)
$TextBox1.Font = $FontText