Windows Develop Bookmark and Share   
 index > Windows Forms General > Simple Question; Racking Brain; headache... Using an Array to create product, price, quanity
 

Simple Question; Racking Brain; headache... Using an Array to create product, price, quanity

Hello!

Ok so I am trying to make a simple program that will allow the use of a combobox and an array.

I am using an combobox as a dropdownlist with the 'products' selected.

My question is I am having problems getting to quanity/total items... and using the listbox to 'sum' the total?

Here is the code... kinda goofy/simple question but my head hurts!

Any help or suggestions would be highly helpful. I have commented the areas of help and labelled everything approperatly.

Thanks danielle

namespace WindowsApplication1

{

public partial class Form1 : Form

{

string[] listOfCourses = new string[5];

decimal[] listOfInstructos = new decimal[5];

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

//

//my array

//

listProducts[0] = "Word";

listProducts[1] = "Excel";

listProducts[2] = "Frontpage";

listProducts[3] = "Access";

listPrices[0] = 10.00m;

listPrices[1] = 20.00m;

listPrices[2] = 30.00m;

listPrices[3] = 40.00m;

cboBoxProduct.DataSource = listProducts;

cboBoxPrice.DataSource = listPrices;

cboBoxProduct.SelectedIndex = -1;

cboBoxPrice.SelectedIndex = -1;

}

private void cboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)

{

cboBoxPrice.SelectedIndex = cboBoxProduct.SelectedIndex;

}

private void btnAddProduct_Click(object sender, EventArgs e)

{

listBox1.Items.Add(cboBoxProduct.SelectedItem);

listBox2.Items.Add(cboBoxPrice.SelectedItem);

}

private void btnTotal_Click(object sender, EventArgs e)

{

//struggling here

//

listBox4.Items.Add(listBox2.Text);

//

// struggling here, wanting this button to give me total as in the total cost of purchase...

// wanting my third list box to have the quanity of order and update without repeat items in list box.

// I know my program is simple but I am learning so give me time...

}

}

}

dmartin6  Monday, February 18, 2008 3:38 PM

Code Snippet

public partial class Form1 : Form

{

decimal total = 0;

public Form1()

{

InitializeComponent();

string[] listProducts = new string[4];

decimal[] listPrices = new decimal[4];

listProducts[0] = "Word";

listProducts[1] = "Excel";

listProducts[2] = "Frontpage";

listProducts[3] = "Access";

listPrices[0] = 10.00m;

listPrices[1] = 20.00m;

listPrices[2] = 30.00m;

listPrices[3] = 40.00m;

cboBoxProduct.DataSource = listProducts;

cboBoxPrice.DataSource = listPrices;

cboBoxProduct.SelectedIndex = -1;

cboBoxPrice.SelectedIndex = -1;

}

private void btnAddProduct_Click(object sender, EventArgs e)

{

listBox1.Items.Add(cboBoxProduct.SelectedItem.ToString());

cboBoxPrice.SelectedIndex = cboBoxProduct.SelectedIndex;

listBox2.Items.Add(cboBoxPrice.SelectedItem.ToString());

listBox3.Items.Clear();

total += (decimal)cboBoxPrice.SelectedItem;

listBox3.Items.Add(total.ToString());

}

ronan001  Monday, February 18, 2008 7:25 PM

Ok... so I have kept reading the forums and other sites (sorry!) as well as my books on arrays...

I keep getting more responses or wanting to use VB instead... gr!

Ok would this work? I dunno how to actually word it tho...

{

decimal[] total = new decimal[1];

total[0] = foreach listBox2.Items(total);

this listBox2.Text = total;

}

I know I need to define the process but I am not sure HOW to get what I want...

Also the quanity is killing me ;/

Any and all help suggestions are welcome!

D

dmartin6  Monday, February 18, 2008 3:54 PM

Code Snippet

public partial class Form1 : Form

{

decimal total = 0;

public Form1()

{

InitializeComponent();

string[] listProducts = new string[4];

decimal[] listPrices = new decimal[4];

listProducts[0] = "Word";

listProducts[1] = "Excel";

listProducts[2] = "Frontpage";

listProducts[3] = "Access";

listPrices[0] = 10.00m;

listPrices[1] = 20.00m;

listPrices[2] = 30.00m;

listPrices[3] = 40.00m;

cboBoxProduct.DataSource = listProducts;

cboBoxPrice.DataSource = listPrices;

cboBoxProduct.SelectedIndex = -1;

cboBoxPrice.SelectedIndex = -1;

}

private void btnAddProduct_Click(object sender, EventArgs e)

{

listBox1.Items.Add(cboBoxProduct.SelectedItem.ToString());

cboBoxPrice.SelectedIndex = cboBoxProduct.SelectedIndex;

listBox2.Items.Add(cboBoxPrice.SelectedItem.ToString());

listBox3.Items.Clear();

total += (decimal)cboBoxPrice.SelectedItem;

listBox3.Items.Add(total.ToString());

}

ronan001  Monday, February 18, 2008 7:25 PM

You can use google to search for other answers

Custom Search

More Threads

• How to copy files into remote computers?
• No handle for certain buttons and checkboxes?
• Opening multiple files at once - Not working properly
• beginner question
• Form position with drag/drop
• How to get modifed data out of the propertygrid
• Help file Window open.
• form hangs when trying to thread
• RichTextBox scrolling
• Vista style windows in C#?