The code below is what I'm having problems with... The combobox part is getting me angry and i've searched everywhere, code guru, msdn, stackoverflow, daniweb... And I cant figure it out. Its for a game my friend plays. I play and quit on and off.. I decided to do a calculator for him..

Problem: Cannot figure out how to determine which item the person clicked in the combobox... I will post a picture of the program in the attachments and the project folder.

//Snippet that Im having trouble with... + My attempt.

private: System::Void comboBox2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
		if (comboBox1.SelectedText == "Chaeldar (Lost City)")
        {
			 int TPOC = Convert::ToInt32((c1)+ '12');    
			 this->textBox2->Text = TPOC.ToString();
//Attempted to add 12 to the value from textbox1(inputted by the user) when this option from the combo box is selected and then put that answer in textbox2.

        }
        else if (comboBox2.SelectedText == "Duradel/Lapalok (Shilo Village)")
        {
          
// add 13 to textbox1 value if this option is selected from the combobox.
        }
}
//Full Program code. Problem at line 348..

#pragma once

namespace SlayerCalculator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::ComboBox^  comboBox1;
	private: System::Windows::Forms::Label^  TaskLabel;
	private: System::Windows::Forms::ComboBox^  comboBox2;
	private: System::Windows::Forms::Label^  MasterLabel;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::TextBox^  textBox2;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::TextBox^  textBox4;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::TextBox^  textBox5;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::TextBox^  textBox6;
	private: System::Windows::Forms::TextBox^  textBox7;
	private: System::Windows::Forms::Label^  label7;
	private: System::Windows::Forms::TextBox^  textBox8;
	private: System::Windows::Forms::Label^  label8;



	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->TaskLabel = (gcnew System::Windows::Forms::Label());
			this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this->MasterLabel = (gcnew System::Windows::Forms::Label());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->textBox4 = (gcnew System::Windows::Forms::TextBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->textBox5 = (gcnew System::Windows::Forms::TextBox());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->textBox6 = (gcnew System::Windows::Forms::TextBox());
			this->textBox7 = (gcnew System::Windows::Forms::TextBox());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->textBox8 = (gcnew System::Windows::Forms::TextBox());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(578, 175);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Calculate";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// comboBox1
			// 
			this->comboBox1->AutoCompleteMode = System::Windows::Forms::AutoCompleteMode::Suggest;
			this->comboBox1->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::ListItems;
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(136) {L"Abberant Spectres", L"Abyssal Demons", L"Ankou", 
				L"Aquanites", L"", L"", L"Banshees", L"Basilisks", L"Bats", L"Bears", L"Birds", L"Black Demons", L"Bloodvelds", L"Blue Dragons", 
				L"Brine Rats", L"Bronze Dragons", L"", L"", L"Catablepons", L"Cave Bugs", L"Cave Crawlers", L"Cave Horrors", L"Cave Slimes", 
				L"Cockatrices", L"Cows", L"Crawling Hands", L"Crocodiles", L"", L"", L"Dagannoths", L"Dark Beasts", L"Desert Lizards", L"Dogs", 
				L"Dust Devils", L"Dwarves", L"", L"", L"Earth Warriors", L"Elves", L"", L"", L"Fever Spiders", L"Fire Giants", L"Flesh Crawlers", 
				L"", L"", L"Gargoyles", L"Ghosts", L"Ghouls", L"Goblins", L"Greater Demons", L"Green Dragons", L"", L"", L"Harpie Bug Swarms", 
				L"Hellhounds", L"Hill Giants", L"Hobgoblins", L"", L"", L"Ice Giants", L"Ice Strykewyrms", L"Ice Warriors", L"Icefiends", L"Infernal Mages", 
				L"Iron Dragons", L"", L"", L"Jellies", L"Jungle Horrors", L"Jungle Strykewyrms", L"", L"", L"Kalphites", L"Killerwatts", L"Kurasks", 
				L"", L"", L"Lesser Demon", L"Living Rock Creatures", L"", L"", L"Minotaurs", L"Mithril Dragons", L"Mogres", L"Molanisks", L"Monkeys", 
				L"Moss Giants", L"Mutated Zygomites", L"", L"", L"Nechryaels", L"", L"", L"Orgres", L"Other Worldly Beings", L"", L"", L"Pyrefiends", 
				L"", L"", L"Red Dragons", L"Rockslugs", L"", L"", L"Scarabite Minions", L"Scorpions", L"Sea Snakes", L"Shaddow Warriors", L"Shades", 
				L"Skeletal Wyverns", L"Skeletons", L"Spiders", L"Spiritual Mages", L"Spiritual Warriors", L"Steel Dragons", L"Suqahs", L"", L"", 
				L"Terror Dogs", L"Trolls", L"Turoths", L"TzHaar", L"", L"", L"Vampires", L"", L"", L"Wall Beasts", L"Warped Tortoises", L"Waterfiends", 
				L"Werewolves", L"Wolves", L"", L"", L"Zombies"});
			this->comboBox1->Location = System::Drawing::Point(33, 285);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(162, 21);
			this->comboBox1->TabIndex = 1;
			this->comboBox1->Text = L"Type or Click-Down";
			this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
			// 
			// TaskLabel
			// 
			this->TaskLabel->AutoSize = true;
			this->TaskLabel->Location = System::Drawing::Point(30, 268);
			this->TaskLabel->Name = L"TaskLabel";
			this->TaskLabel->Size = System::Drawing::Size(82, 13);
			this->TaskLabel->TabIndex = 2;
			this->TaskLabel->Text = L"Task/Monsters:";
			// 
			// comboBox2
			// 
			this->comboBox2->AutoCompleteMode = System::Windows::Forms::AutoCompleteMode::Suggest;
			this->comboBox2->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::ListItems;
			this->comboBox2->FormattingEnabled = true;
			this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^  >(7) {L"Chaeldar (Lost City)", L"Duradel/Lapalok (Shilo Village)", 
				L"Kuradal (Ancient Cavern)", L"Mazchna (Canifis)", L"Sumona (Pollnivneach)", L"Turael/Spria (Burthorpe)", L"Vannaka (Edgeville Dungeon)"});
			this->comboBox2->Location = System::Drawing::Point(33, 178);
			this->comboBox2->Name = L"comboBox2";
			this->comboBox2->Size = System::Drawing::Size(162, 21);
			this->comboBox2->Sorted = true;
			this->comboBox2->TabIndex = 3;
			this->comboBox2->Text = L"Type or Click-Down";
			this->comboBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox2_SelectedIndexChanged);
			// 
			// MasterLabel
			// 
			this->MasterLabel->AutoSize = true;
			this->MasterLabel->Location = System::Drawing::Point(30, 162);
			this->MasterLabel->Name = L"MasterLabel";
			this->MasterLabel->Size = System::Drawing::Size(74, 13);
			this->MasterLabel->TabIndex = 4;
			this->MasterLabel->Text = L"Slayer Master:";
			this->MasterLabel->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(266, 178);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(33, 20);
			this->textBox1->TabIndex = 5;
			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(235, 162);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(108, 13);
			this->label1->TabIndex = 6;
			this->label1->Text = L"Current Slayer Points:";
			// 
			// textBox2
			// 
			this->textBox2->Location = System::Drawing::Point(418, 178);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(61, 20);
			this->textBox2->TabIndex = 7;
			this->textBox2->TextChanged += gcnew System::EventHandler(this, &Form1::textBox2_TextChanged);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(376, 162);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(138, 13);
			this->label2->TabIndex = 8;
			this->label2->Text = L"Total Points On Completion:";
			// 
			// textBox3
			// 
			this->textBox3->Location = System::Drawing::Point(397, 264);
			this->textBox3->Name = L"textBox3";
			this->textBox3->Size = System::Drawing::Size(100, 20);
			this->textBox3->TabIndex = 9;
			this->textBox3->TextChanged += gcnew System::EventHandler(this, &Form1::textBox3_TextChanged);
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(415, 248);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(61, 13);
			this->label3->TabIndex = 10;
			this->label3->Text = L"Current XP:";
			// 
			// textBox4
			// 
			this->textBox4->Location = System::Drawing::Point(266, 264);
			this->textBox4->Name = L"textBox4";
			this->textBox4->Size = System::Drawing::Size(33, 20);
			this->textBox4->TabIndex = 11;
			this->textBox4->TextChanged += gcnew System::EventHandler(this, &Form1::textBox4_TextChanged);
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(248, 248);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(70, 13);
			this->label4->TabIndex = 12;
			this->label4->Text = L"Current Level";
			// 
			// textBox5
			// 
			this->textBox5->Location = System::Drawing::Point(397, 319);
			this->textBox5->Name = L"textBox5";
			this->textBox5->Size = System::Drawing::Size(100, 20);
			this->textBox5->TabIndex = 13;
			this->textBox5->TextChanged += gcnew System::EventHandler(this, &Form1::textBox5_TextChanged);
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(426, 303);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(58, 13);
			this->label5->TabIndex = 14;
			this->label5->Text = L"Target XP:";
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(248, 303);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(70, 13);
			this->label6->TabIndex = 15;
			this->label6->Text = L"Target Level:";
			// 
			// textBox6
			// 
			this->textBox6->Location = System::Drawing::Point(266, 318);
			this->textBox6->Name = L"textBox6";
			this->textBox6->Size = System::Drawing::Size(33, 20);
			this->textBox6->TabIndex = 16;
			this->textBox6->TextChanged += gcnew System::EventHandler(this, &Form1::textBox6_TextChanged);
			// 
			// textBox7
			// 
			this->textBox7->Location = System::Drawing::Point(555, 318);
			this->textBox7->Name = L"textBox7";
			this->textBox7->Size = System::Drawing::Size(100, 20);
			this->textBox7->TabIndex = 17;
			this->textBox7->TextChanged += gcnew System::EventHandler(this, &Form1::textBox7_TextChanged);
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(575, 302);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(65, 13);
			this->label7->TabIndex = 18;
			this->label7->Text = L"XP Needed:";
			// 
			// textBox8
			// 
			this->textBox8->Location = System::Drawing::Point(555, 268);
			this->textBox8->Name = L"textBox8";
			this->textBox8->Size = System::Drawing::Size(100, 20);
			this->textBox8->TabIndex = 19;
			this->textBox8->TextChanged += gcnew System::EventHandler(this, &Form1::textBox8_TextChanged);
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(555, 247);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(114, 13);
			this->label8->TabIndex = 20;
			this->label8->Text = L"XP Gained From Task:";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->AutoSize = true;
			this->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
			this->ClientSize = System::Drawing::Size(716, 381);
			this->Controls->Add(this->label8);
			this->Controls->Add(this->textBox8);
			this->Controls->Add(this->label7);
			this->Controls->Add(this->textBox7);
			this->Controls->Add(this->textBox6);
			this->Controls->Add(this->label6);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->textBox5);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->textBox4);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->textBox3);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->textBox2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->MasterLabel);
			this->Controls->Add(this->comboBox2);
			this->Controls->Add(this->TaskLabel);
			this->Controls->Add(this->comboBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Slayer Calculator";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
		 }

private: System::Void comboBox2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
		if (comboBox1.SelectedText == "Chaeldar (Lost City)")
        {
			 int TPOC = Convert::ToInt32((c1)+ '12');
			 this->textBox2->Text = TPOC.ToString();
        }
        else if (comboBox2.SelectedText == "Duradel/Lapalok (Shilo Village)")
        {
          
        }
}

private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 int c1 = Convert::ToInt32(this->textBox1->Text);
			 int c2 = Convert::ToInt32(this->textBox2->Text);
			 int c3 = Convert::ToInt32(this->textBox3->Text);
			 int c4 = Convert::ToInt32(this->textBox4->Text);
			 int c5 = Convert::ToInt32(this->textBox5->Text);
			 int c6 = Convert::ToInt32(this->textBox6->Text);
			 int c7 = Convert::ToInt32(this->textBox7->Text);
			 int c8 = Convert::ToInt32(this->textBox8->Text);

			 int XPNeeded = Convert::ToInt32((c5)-(c3));
			 this->textBox7->Text = XPNeeded.ToString(); 
		 }
private: System::Void textBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox3_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox4_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox5_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox6_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox7_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox8_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}

You want something along these lines

int tb1value;
Int32::TryParse(textBox1->Text,tb1value); //enclose this in an if to make your own error handling
int tb2value = tb1value+comboBox1->SelectedIndex+12; 
//it doesn't matter what's in the box, just use the offset
textBox2->Text = tb2value.ToString();

Wow thats exactly what I wanted... saw that on a youtube video but the part I did not understand is the (tb1value+comboBox1->SelectedIndex+12;)... The selected index part is the piece of that line i dont understand..

I wanted it so that if they select the first option in the box, add 12.. if the second option add 13 if third add whatever.. does that do it for me? what does that selected index do? I know its if they select and option but does this apply to a specific option or all options in the combobox?

Would I do.. if (comboBox1.SelectedIndex == "Chaeldar (Lost City)") add 12? or 13? or 19? or whatever? (I know how to add to it)

If you have the first option selected (option 0) it returns 0 (total +12), second option (option 1) it returns 1 (total +13). Chaeldar would add a total of 12. Just make a form with a combobox on it and play around with it a little. You don't need the if statement like you have it because the box is agnostic to the actual contents, as long as you keep everything in the right order it's fine.

but does this apply to a specific option or all options in the combobox?

Every option has an index associated with it.

I tried making a form with just a combobox.. I couldnt get it to work..

Every option I selected added +12 to the value... resulting in total of 11..

example: i entered 0, it added 12 to it.. resulted in 11.. Guess cuz the index is -1 :S
when I seletected first option, same thing, second option, same thing, third, same answer.

NVM Got it to work.. Now it adds 12 and stuff but when I select option 2, it adds 13, option 3 it adds 14... I wanted to choose what to add to each option... do you or anyone know how to do that?

Got it!! Thank bro your the best... just the little hints u gave.. Code incase anyone wants it:

private: System::Void comboBox2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 comboBox2->SelectedItem->ToString();
			 if(comboBox2->SelectedItem == "123"){
				int tb1;
				Int32::TryParse(textBox1->Text,tb1); //enclose this in an if to make your own error handling
				int tb2 = tb1+comboBox2->SelectedIndex+10; 
				//it doesn't matter what's in the box, just use the offset
				textBox2->Text = tb2.ToString();
			 }
			 else if(comboBox2->SelectedItem == "456"){
				 int tb3;
				 Int32::TryParse(textBox1->Text,tb3);
				 int tb4 = tb3+comboBox2->SelectedIndex+14;
				 textBox2->Text = tb4.ToString();
			 }

I think if nothing is selected the index is -1.

Oh, I thought that's what you wanted (to have the progression go by 1 each step). Ok. Well, make an array: cli::array<int> ^ pointsarr = {4,2,7,5,8,9,22}; and add pointsarray[comboBox1->SelectedItem] to your total instead.

Oh, our posts crossed. Okay, glad you got it to work!!

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.