BEGGINER CLR C++ FORM indications needed

Apr 21, 2014 at 3:15am
So first of all, thanks for your help in advance. This is my first post, this is very important to me, because this is regarding my thesis degree project.

I study electronics engineering, and throughout the carreer we don't learn nothing about windows programming, but i wanted to add to my thesis a simple windows program. it will be a c++ clr form very simple (for you experienced ones) which only will send a little USB data to a microcontroller (pic18f4550) and this later will do all the work.
So to the point:
I'm making a simple windows with 3 tabs, each tab would be a "subject". the 3 tabs are the same, just that each tab will send one data string through USB port (total 3 data strings).
I have set the form like this:
http://imageshack.com/a/img842/157/kb3r.png

so i need to put some "field" or "box" by the labels with pre-set "values" or "character strings" wich should be auto filled when i select one of the elements from the "ComboBox" in the top left corner.

I wanted to ask you which element should i use for this and how should a link the element from the "combobox" to the filling of these 3 fields.

this is visual studio 2010.

For now, thanks and please help me.

Last edited on Apr 21, 2014 at 3:17am
Apr 21, 2014 at 3:51am
> which element should i use for this

A (readonly) TextBox
http://msdn.microsoft.com/en-us/library/System.Windows.Forms.TextBox(v=vs.90).aspx


> how should a link the element from the "combobox" to the filling of these 3 fields.

Subscribe to the SelectedIndexChanged event of the ComboBox.
And in the event handler, update the Text property of the TextBox.
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindexchanged(v=vs.90).aspx
Apr 21, 2014 at 4:21pm
Thanks JLBorges, could you expand a littlle more the Subscribe thing in the combobox please? i quite dont get it yet.
Apr 21, 2014 at 10:59pm
See the example on the linked page (click on the C++ tab):

Subscribe to the event:
1
2
3
4
      // Associate the event-handling method with the  
      // SelectedIndexChanged event. 
      this->ComboBox1->SelectedIndexChanged +=
         gcnew System::EventHandler( this, &Form1::ComboBox1_SelectedIndexChanged );


The event handler:
1
2
3
4
5
6
7
   // This method is called when the user changes his or her selection. 
   // ...
   void ComboBox1_SelectedIndexChanged( Object^ sender, System::EventArgs^ e )
   {
        // set the text of the TextBox
        TextBox->Text = ..... ;
   }
Apr 22, 2014 at 12:41pm
Thanks, i've got it now some tweaks, and i'm done.
Should i use a "switch case" to identify the selected item (find string exact) in the combobox and then put the acording text into the text box? or should i use "nested" if else?
Apr 22, 2014 at 2:05pm
> identify the selected item in the combobox

Something like this should work:

1
2
3
4
5
6
7
8
   void ComboBox1_SelectedIndexChanged( Object^ sender, System::EventArgs^ e )
   {
        
        String text_in_combobox = ComboBox1.GetItemText( ComboBox1.SelectedItem );
        // ...  
        // set the text of the TextBox
        TextBox->Text = ..... ;
   }
Apr 23, 2014 at 3:06pm
I JUST WANTED to thank you and tell you that i managed to make it work like this:


c++/CLI programing visual studio 2010. HANDLER FOR THE EVENTO SELECT ITEM IN A COMBOBOX (this solution was done by reading forums is not copypaste, worked for me):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
			{
			ComboBox^ comboBox = (ComboBox^)(sender);
			int index = 10; //for initializa any value
			index = comboBox1->SelectedIndex;
			Object^ selectedItem = comboBox1->SelectedItem;
								
			if(index == 0)
				{
				react1texttab1->Text= "222";
				react2texttab1->Text= "222";
				time1texttab1->Text= "222";
				}
			else
				{
				if(index == 1)	
					{
					react1texttab1->Text= "ggg";
					react2texttab1->Text= "ggg";
					time1texttab1->Text= "ggg";
					}
				else
					{
					react1texttab1->Text= "1a1a";
					react2texttab1->Text= "1a1a";
					time1texttab1->Text= "1a1a";
					}		
				}
			}



I hope this helps you all
Topic archived. No new replies allowed.