C# GUI help

thesadguy

Active Member
Joined
Nov 29, 2008
Messages
70
Reaction score
0
I have a modal dialog Form that holds a few controls; a few ComboBoxes, some CheckBoxes, etc. I generate an event when "OK" or "Cancel" is clicked, but I'm having trouble figuring out how to reference the values stored in the ComboBoxes and CheckBoxes.

Can anyone help me, even if only with methodology for checking?
 
I'm not completely sure what you're trying to do but I'll list a few examples in an attempt to help you:

If you simply want to access the values stored in a ComboBox then you either need to use the comboBox.SelectedIndex property to get the index of the selected item. The best option in my opinion is to put the object references directly into a combo box, so say you are storing a bunch of clients and the object type is Client.

If you have the clients as an array called cleints its as simple as:
ComboBox.Items.AddRange(clients);

Then to get the selected client you simply:
Client selectedClient = ComboBox.SelectedItem;

Remember selectedClient is a object pointer in reality, if you don't understand then I'll explain again in another post because it's quite long winded :)

For checkboxes you can get the value by using:

CheckBox.Checked;

That returns a boolean value.

Now this is all pretty straight forward beginners stuff so I assume what you're really having trouble with is accessing the values outside of the current context?

In that case simply use a property as you would for any other class:

public object comboBox1SelectedItem
{
get
{
return comboBox1.SelectedItem;
}
}

If nothing I say makes any sense post again with what exactly you want to do and I'll explain again with more specific info ;)
 
Thanks for your help, Gnome!

Was useful in my troubleshooting.

Turned out I was mixing up a few things.

Moral of the story? Keep a graphical representation (e.g. Class Diagram) handy of your class structure.

Thanks again, and sorry for the trouble.
 
heh, np :)

If you need help with anything else just post, I'm bored :p
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X