I assigned String ^ Box1 like this.

String^ Box1;
Box1 = comboBox1->SelectedItem->ToString();

What I am trying to do now and wonder is if it is possible is to put
"comboBox1->SelectedItem->ToString()" to a vector.

For the std:: it would look like this:

std::vector<string> StdVector;
StdVector[0] = "comboBox1->SelectedItem->ToString()";

My real question here is this now. First I am not sure how to declare a vector in the System::IO but as an example but I know it is not possible to combine String^ and std::vector.

Will this work or do you have to write
"comboBox1->SelectedItem->ToString()" out ?

Box1 = StdVector[0];

it would be easier (and also more efficient) if you use a cliext::vector<> instead of a std::vector<> note: requires VC++ 9 (2008)

#include <cliext/vector>
using namespace cliext ;

// ...
{
  // ...
  vector< String^ >^ vec = gcnew vector< String^ > ;
  vec->push_back( comboBox1->SelectedItem->ToString() ) ;
  String^ Box1 = vec[0] ;
  // ...
}

Thank you. I do have Visual 9.0 2008 so this works though. I will give 2 examples of what I am doing. The first one works but what I want is to replace it with the second. Both examples compiles but the second example with the Array terminates the program when I am running it.
I keep wonder why and what the differences are ?

As seen I am doing a path-searchway.

First: (This example works)

String^ SymbolenGroup;
Box1 = comboBox1->SelectedItem->ToString();
String^ path = "C:\\Glob\\Groups\\" + Box1 + ".txt";

Second: (The one I would like to work, with the array)

#include <cliext/vector>
using namespace cliext ;

cliext::vector< String^ >^ Box1 = gcnew cliext::vector< String^ >;
Box1[0] = comboBox1->SelectedItem->ToString();
String^ path = "C:\\Glob\\Groups\\" + Box1[0] + ".txt";

So in the first example + Box1 + works and in the second example + Box1[0] + doesn´t work.
I get an error when running the program here "Unhandled exception has occured"


it would be easier (and also more efficient) if you use a cliext::vector<> instead of a std::vector<> note: requires VC++ 9 (2008)

#include <cliext/vector>
using namespace cliext ;

// ...
{
  // ...
  vector< String^ >^ vec = gcnew vector< String^ > ;
  vec->push_back( comboBox1->SelectedItem->ToString() ) ;
  String^ Box1 = vec[0] ;
  // ...
}
#include <cliext/vector>
using namespace cliext ;

// ...
// create an empty vector
cliext::vector< String^ >^ Box1 = gcnew cliext::vector< String^ >;

// this will not work; there is no space in the vector
// Box1[0] = comboBox1->SelectedItem->ToString();

// this would; make space for the element
Box1->push_back( comboBox1->SelectedItem->ToString() ) ;

// fine; Box1 now has one element and Box1[0] retrives it
String^ path = "C:\\Glob\\Groups\\" + Box1[0] + ".txt";
// however Box1[1] is an error here; there is only one element right now.

it would be a good idea to give your variables more meaningful identifiers than ComboBox1, Box23 etc. like file_names_combobox or select_file_combo instead of ComboBox1.

Thanks, vijayan121. That did work fine !

I forgot about the space that you mentioned also.

I have a wondering here. Is it correct to do pushback like this:

Box1->push_back( comboBox1->SelectedItem->ToString() ) ;
Box1->push_back( comboBox2->SelectedItem->ToString() ) ;

Do comboBox1 get place Box1[0] and
do comboBox2 get place Box1[1] in this case when writing them under eachother like this ?

Becase when doing like this the code compiles but the program terminates when runned.
If I take the second line away with comboBox2 and run the program it works fine.

I am using reference to Box1[0] in both cases.

Could it be that comboBox2->SelectedItem is a NULL reference? Calling Box1->push_back() like you do is OK.

Yes it was depending on that. The selected Item was a NULL reference.

I changed SelectedTiem to this instead and then it is ok if it is a "NULL reference"

Box1->push_back( comboBox2->Text->ToString() ) ;

Could it be that comboBox2->SelectedItem is a NULL reference? Calling Box1->push_back() like you do is OK.

This question has already been answered. Start a new discussion instead.