-
Working with ComboBoxes
Hello!
I have a basic C background an am experimenting C# for quick Windows development. I am amazed at the sheer simplicity of writing GUIs with Windows.Forms, but now I have stumbled into a question.
I have a program that will parse a text file and populate a ComboBox1 with entries. I also have a second ComboBox which has a fixed list of parameters. Now how can I link the two so that an entry in ComboBox #1 is associated with a specific ComboBox2.SelectedIndex ?
Should I create an array of ComboBox2.SelectedIndexes (that is, an array of integers) for each ComboBox1 entry and then update Combo 2 on ComboBox1.SelectedIndexChanged? I can see that working, but what about if I want to have more parameters ComboBoxes associated to each entry? What are the options to work with this other than this?
In C I think I could use a struct, but I'm not yet confident using classes in C# or whatever the equivalente would be.
Thanks in advance.
-
What do you want to do exactly, associate doesn't really tell me anything specific personally.
------------
Make sure you understand what a reference type and a value type is in C# to associate those meaning with C (typically pointer-reference, value-er value). Try reading a simple tutorial about classes. There are structs+functions that are performed on the struct-members. Well, that is the basic idea. If you do this
Code:
public class My
{
public int a;
public int b;
public int getA() { return a; }
public int getB() { return b; }
}
you have a simple class. You a can use it as a struct (typedefed)
Code:
My var;
var.a = 10;
var.b = 20;
You can use the functions also
Code:
....
int x = var.getA(); //will give x==10
int y = var.getB(); //will give y==20
well, there are more of course. You can also define a struct in C#, but use classes to learn