Thread: Working with ComboBoxes

  1. #1
    Registered User
    Join Date
    Aug 2008

    Working with ComboBoxes


    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.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    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

    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)
    My var;
    var.a = 10;
    var.b = 20;
    You can use the functions also
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM