简体   繁体   中英

How do I fill a combo box bases on other combo boxes

I have a class that creates a bunch(30) of hex and text strings for commands to be sent to a device. All the commands use similar parameters. Here are a few examples.

public string TmclRotateRight(bool bin, string address, int motor, int value) public string TmclRotateLeft(bool bin, string address, int motor, int value) public string TmclStoreGlobalParameter(bool bin, string address, string type, int motor) public string TmclSetCoordinate(bool bin, string address, string type, int motor, int value)

I'm building the UI with combo-boxes for the commands and parameters. Basically I want the user to select the first combo-box, the command, and the other combo-boxes are then populated with the appropriate parameters for that command. Most of the parameters only have a few options except for value which can be just about anything.

What's the best way to accomplish this?

Thanks!

One way to go is to use databound comboboxes. You can set any enumerable type (eg Array or List ) as the other ComboBox 's DataSource property during the SelectedIndexChanged event of your command ComboBox .

You can pack all of the comboboxes' SelectedItem properties into an Object array and use this as the parameters to call your mehtods via reflection.

In case of your value parameter, I would suggest using a TextBox or NumericUpDown to allow arbitrary numeric input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM