Hi all. I have a GUI form that has a combobox bound to a csv using .datasource. The csv records (Printers and their IP addresses) populate the combobox but not in the way i wanted them to. I currently see each record in the format printername, IPAddress (ACCPrint-04, 10.10.20.121). I’d like to see just the printer name in the combo but be able to use the IP in the add_SelectedIndexChanged event after selecting a printer (to open the web console for the selected printer)
Code creating and populating the combobox. PrinterIPtxt is my test text box where i am attempting to display only the IP address:
#CREATE AND ADD PRINTERS COMBOBOX
$PrinterCombo = New-Object system.Windows.Forms.ComboBox
$PrinterCombo.location = New-Object system.Drawing.Size(310,470)
$PrinterCombo.size = New-Object System.Drawing.Size(200,20)
$PrinterCombo.DropDownStyle = "Dropdownlist"
$PrinterCombo.AutoCompleteMode = "Suggest"
$PrinterCombo.FlatStyle = "Flat"
$PrinterCombo.Items.Clear()
$Header = "PrinterName", "PrinterIP"
$PrinterList = Import-Csv -Delimiter "`t" -Path "C:\Scripts\PoShForm\PrintersandPortsFixed.csv" -Header $Header | select -ExpandProperty PrinterName
$PrinterCombo.DataSource = ($PrinterList)
$PrinterCombo.DisplayMember = 'PrinterName'
$PrinterCombo.ValueMember = 'PrinterIP'
$Form.controls.add($PrinterCombo)
$PrinterCombo.add_SelectedIndexChanged({GetPrinterSelected})
$PrinterIPtxt = New-Object system.Windows.Forms.TextBox
$PrinterIPtxt.location = New-Object system.Drawing.Size(310,500)
$PrinterIPtxt.size = New-Object System.Drawing.Size(100,20)
$Form.Controls.Add($PrinterIPtxt)
Code fired at event:
function GetPrinterSelected {
$PrinterIPtxt.Text = $PrinterCombo.SelectedItem
} #end GetPrinterSelected
I hope i post this ok, first attempt here. Thanks in advance for all your help on this, i don’t have much more hair to pull out.