Click here to Skip to main content
15,891,718 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I was curious if I should use a listbox or combobox to look up warehouse part numbers and then fire an event if it is clicked. I want to be able to click that number and then send a specific command out a serial port. I currently use a selection of hyperlinks to do this but there are now to many and a dropdown list would be helpful to select from and fire the same command as if it was the hyperlink.

Here is my code for when a hyperlink is clicked for part HC1_101... could I replace this with a listbox to send the same command? Can I just add the links to the dropdown list?

C#
private void linkLabel_HC1_101_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    if (serialPort1.IsOpen)
    {
        var content = new List<byte>();
        content.Add(2);
        content.AddRange(Encoding.ASCII.GetBytes("01P00101##"));
        content.Add(3);
        byte[] buffer = content.ToArray();
        serialPort1.Write(buffer, 0, buffer.Length);
    }
}
Posted
Comments
Ralf Meier 15-Jul-15 14:15pm    
To use a Combobox or a Listbox depends on what you find better for your application.
Both fire an Event if their selection was changed or if they are clicked or whatever you want or need. I don't understand the problem at the moment ...

"Which is better?" is a question we can hardly give a correct and precise answer. We don't know anything of your project.

Here are some MSDN links to the Windows Forms version of the controls:
ComboBox class[^]
ListBox class[^]

In their event lists, you will find which delegate (event handler) you will have to use.
 
Share this answer
 
The choice depends solely on what you want. ComboBox adds a text box input on top. What are you going to do with this part of control? If you want to input something in it (even for the purpose of search-like selection style), you need ComboBox. If you want to be able to input some text not shown in the list, you also need ComboBox. By the way, one possible application of the list part would be storing the history in input in text box part. In all other cases, it's ListBox.

As simple as that.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900