|
-
December 26th, 2007, 04:03 AM
#1
listbox not showing up
the listbox isn't showing up here for some reason. I want to have a pull down menu between Ontario and Quebec which outcome is affected by the user's choice.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace distancecalc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void CalculateButton_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
string customers;
double costperyear; // will be affected by whether user chooses Ontario or Quebec
if (listBox1.SelectedItem == "Ontario") //assuming you put strings into the list box
costperyear = 0.1001;
else
costperyear = 0.0663; // rate dependint on the choice user choses on their listbox
double KwhRating = 0.0;
double years = 0.0;
double.TryParse(textBox1.Text, out KwhRating);
double.TryParse(textBox2.Text, out years);
double kwcostOntario = 0.1001;
double kwcostQuebec = 0.0663;
double totalcost = KwhRating * years * costperyear;
textBox3.Text = totalcost.ToString();
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.Items.Add("Ontario");
listBox1.Items.Add("Quebec");
//kwh prices in Ontario are $0.1001
//kwh prices in Quebec $0.0663
// I am tring to make it so that if the user selecs "Ontario
//then "costperyear" would = 0.1001 the list box also isnt showing up
//but the problem is the listbox isnt even showing up, it is blank
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
-
December 26th, 2007, 06:54 AM
#2
Re: listbox not showing up
 Originally Posted by chipninja
the listbox isn't showing up here for some reason. I want to have a pull down menu between Ontario and Quebec which outcome is affected by the user's choice.
What do you mean by this ? listbox isn't showing up here ? do u mean you do not see the listbox on the designer ? or you dont get the reference of listbox when you type ListBox1 ?
Regards,
MMH
Rate my post if you find it usefull. 
-
December 26th, 2007, 10:33 AM
#3
Re: listbox not showing up
As you added items into the listBox when SelectedIndexChanged events is triggerred, that is not going to trigger until you have items in listbox and select these items.
-
December 26th, 2007, 06:35 PM
#4
Re: listbox not showing up
what I mean is that the lsitbox options are not showing up in my GUI program when I run it. Instead I get a blank space. Should I put the ".Add" in the "Calculate" button??
-
December 26th, 2007, 06:45 PM
#5
Re: listbox not showing up
Whenever I use VS to put entries into a listbox, it does it for me in the InitializeComponent() code that is at the top of your listing.
If anything, put your
Code:
listBox1.Items.Add("Ontario");
listBox1.Items.Add("Quebec");
items just after the InitializeComponent() call that should make it work.
C# - Visual Studio 2005
Frameworks 2.0
-
December 26th, 2007, 07:16 PM
#6
Re: listbox not showing up
omg thank you
that was so simple, yet I couldn't find the solution anywhere. I guess the initialize is used whenver you have a user driven type of tool in the GUI that needs to be selected
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|