AdvancedHMI Software
General Category => Support Questions => Topic started by: bachphi on July 12, 2016, 03:51:51 PM
-
I would like to populate a combobox with part numbers from PLC. The part numbers are UDT like below:
Partnum[0].PartNumber = '1234' 'string
Partnum[1].PartNumber = '2345' 'string
.....
Is there a good way that is similar to getting Com ports into combobox
myPort = IO.Ports.SerialPort.GetPortNames()
For i = 0 To UBound(myPort)
cmbPort.Items.Add(myPort(i))
Next
cmbPort.Text = cmbPort.Items.Item(0)
-
This is how I populate a combobox with ports, which is essentially the same as you have in your post:
'* Retreive available ports and add to combo box
Dim ports() As String = System.IO.Ports.SerialPort.GetPortNames()
Array.Sort(ports)
For i As Integer = 0 To ports.Length - 1
PortName.Items.Add(ports(i))
Next
PortName.Text = ports(0)
Populating a ComboBox with values from a PLC would be very similar:
ComboBox1.Items.Clear()
For i=0 to 1
ComboBox1.Items.Add(EthernetIPForCLXCom1.Read("Partnum[" & i & "].PartNumber"))
Next
-
Thanks, Archie.
I was thinking of using GettagList and if TagName equal to PartNum then populate, but your solution should works!
-
I learned something new, you can also populate a combobox without using the for loop, use DataSource instead.
'* Retrieve available ports and add to combo box
Dim ports() As String = System.IO.Ports.SerialPort.GetPortNames()
Array.Sort(ports)
cmbPortName.DataSource = ports
cmbPortName.SelectedIndex = 0