Hello,

I have written a console version of a program that has 1 menu (5 possible choices). Then after selecting one, it goes into a second screen where you enter the values and eventuelly the calculation takes place.

Now i want the exact same program in a Windows Form version.

- I have added 4 options for my combo box, and they are now listed when i run the form

- The problem if i select 1 option of the combo box how do i let all the buttons,texboxes,labels etc change along? I will try to explain the catch below.

Combo box = 4 different options (basicly its 1 formula getting 4 different values out of it, Wich are Rent, begin amount, end amount, amount of years)

*Rent % => things to fill in : start amount, end amount, amount of years
* start amount => things to fill in: end amount, rent %, amount of years
*end amount => things to fill in: start amount, rent, amount of years
*amount of years => things to fill in start amount, end amount, rent %

So basicly if i select a option from the combo box the textboxes,labels etc have to change along. But in the entire program only 4 textboxes and labels are used.

So if i select Rent from the combo box only the start amount, end amount and amount of years + the calculate button & a label for result should be displayed.

Visa versa if i select any of the others mentioned above.

I have tried looking everywhere but i cannot seem to find a way find out where to link them.

Picture:
[img]http://img689.imageshack.us/img689/8135/17634243.jpg[/img]

Regards.

Recommended Answers

All 4 Replies

Hello.
Not sure if I've got the point .. but I'll take a shot :) What about using ComboBox..::.SelectedIndexChanged Event?

If I'm wrong, please give more details on what troubles are you facing .. e.g. you don't know, how to get value from ComboBox .. or something else.

Hello.
Not sure if I've got the point .. but I'll take a shot :) What about using ComboBox..::.SelectedIndexChanged Event?

If I'm wrong, please give more details on what troubles are you facing .. e.g. you don't know, how to get value from ComboBox .. or something else.

Hello,
Not exactly sure, looks like it.
Although trough that code of msdn i did not got any clearer.
I have added a picture link that hopefully helps describin the problem a bit better.

The labels & textboxes have to change , depending on what i select in the combo box.

Like in the picture if Rentenpercentage (P) is selected following is displayed:
= > Beginkapitaal (K0), Eindkapitaal (Kn), Aantal jaren (N) + the calculate button "bereken & the label result underneath"

If for example Begin kapitaal is selected the following is displayed:
Eind kapitaal (Kn), rentenpercentage (P), Aantal jaren (N) + the calculate button "bereken & the label result underneath"

So i basicly have to put the code somewhere in the combo box "view code" or? Only been making basic Windows forms, and this has me confused.

Regards.

Okies. Now the points of attention in the given example:
ComboBox creating ..

this.ComboBox1 = new System.Windows.Forms.ComboBox();
...

Now to be able to catch and process the events , raised in your combobox in runtime, you should add event handler to it:

// Associate the event-handling method with the 
        // SelectedIndexChanged event.
        this.ComboBox1.SelectedIndexChanged += 
            new System.EventHandler(ComboBox1_SelectedIndexChanged);

Ok, now we have ComboBox, with event handler attached to it. Now all you have to do is implement the logic of this method, which will be raised as soon as Selected Index in your Combobox would be changed. Here's what the example gives:

private void ComboBox1_SelectedIndexChanged(object sender, 
        System.EventArgs e)
    {
        //obtain ComboBox, which was raising this event
        ComboBox comboBox = (ComboBox) sender;

        // Getting selected item from it
        string selectedEmployee = (string) ComboBox1.SelectedItem;
         
        // Working with other controls on the form
        TextBox1.Text = TextBox1.Text+ "\r\n" + selectedEmployee + ": "
            + count;
    }

Okies. Now the points of attention in the given example:

Ok, now we have ComboBox, with event handler attached to it. Now all you have to do is implement the logic of this method, which will be raised as soon as Selected Index in your Combobox would be changed. Here's what the example gives:

private void ComboBox1_SelectedIndexChanged(object sender, 
        System.EventArgs e)
    {
        //obtain ComboBox, which was raising this event
        ComboBox comboBox = (ComboBox) sender;

        // Getting selected item from it
        string selectedEmployee = (string) ComboBox1.SelectedItem;
         
        // Working with other controls on the form
        TextBox1.Text = TextBox1.Text+ "\r\n" + selectedEmployee + ": "
            + count;
    }

Hello, thanks for replying.

I am still confused how exactly i have to put all the labels/textboxes on my form.
For example when i try string Beginkapital (K0) = (string) ComboBox1.SelectedItem;
It gives errors.
Beyond that i still do not understand how to handle the events in the SelectIndexChanged.

Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.