Click to See Complete Forum and Search --> : ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo ^'
krosty4782
October 11th, 2010, 05:46 PM
Hi all.
Im having a problem when i make my program.
The code is:
string ja = "jaja";
ListViewItem item1 = gcnew ListViewItem(ja,0 );
listView1->Items->Add(item1);
And it gives me the following error:
: error C2664: 'System::Windows::Forms::ListViewItem::ListViewItem(System::Runtime::Serialization::SerializationInfo ^,System::Runtime::Serialization::StreamingContext)' : cannot convert parameter 1 from 'std::string' to 'System::Runtime::Serialization::SerializationInfo ^'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\mauri\documents\visual studio 2008\projects\mauri\mauri\Form1.h(192) : error C2664: 'System::Windows::Forms::ListViewItem ^System::Windows::Forms::ListView::ListViewItemCollection::Add(System::String ^)' : cannot convert parameter 1 from 'System::Windows::Forms::ListViewItem' to 'System::String ^'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Thanks
Eri523
October 11th, 2010, 06:43 PM
The error message you get is misleading to some extent, but the bottom line seems to be that there is no ListViewItem constructor that takes an std::string as the first parameter.
One possible solution might be to construct a temporary System::String object from the std::string. As there is a System::String constructor that takes a char *, something like this might work:
ListViewItem item1 = gcnew ListViewItem(gcnew String(ja.c_str()),0 );
But why are you involving an std::string at all? Is this a native/managed interop scenario?
HTH
krosty4782
October 11th, 2010, 07:44 PM
I tried what you have putted and it didnt work.
Im really lost with this... i know how to program in c++ but im trying to use visual studio for the graphic interface and im really lost :s
Eri523
October 11th, 2010, 08:42 PM
Ok, then it looks like we need to see some more sample code demonstrating the problem and/or error messages. Can you post some more? We certainly can't help you just using imagination... ;)
krosty4782
October 11th, 2010, 08:55 PM
Well what i want is to put an item in a listview, but this item need to have a variable as name.
So i create the listview
private: System::Windows::Forms::ListView^ listView1;
Then i inizialize
this->listView1 = (gcnew System::Windows::Forms::ListView());
//
// listView1
//
this->listView1->BackColor = System::Drawing::SystemColors::Window;
this->listView1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(2) {this->columnHeader2, this->columnHeader3});
this->listView1->ForeColor = System::Drawing::SystemColors::InfoText;
this->listView1->Location = System::Drawing::Point(12, 67);
this->listView1->Name = L"listView1";
this->listView1->Size = System::Drawing::Size(260, 97);
this->listView1->TabIndex = 0;
this->listView1->UseCompatibleStateImageBehavior = false;
this->listView1->View = System::Windows::Forms::View::Details;
And finally i do this to add the item:
String ja = "jaja";
ListViewItem item1 = gcnew ListViewItem(ja);
listView1->Items->Add(item1);
The strange is that if i do "ListViewItem item1 = gcnew ListViewItem("text");" there is no problem, so the problem is in the variable i think i have to define it as another type.
In msdn i ve found this:
Initializes a new instance of the ListViewItem class with the specified item text.
ListViewItem (
String^ text
)
So, if i put String^ ja = "jaja" instead of String ja = "jaja" the error is:
error C2664: 'System::Windows::Forms::ListViewItem::ListViewItem(System::String ^)' : cannot convert parameter 1 from 'System::Windows::Forms::ListViewItem ^' to 'System::String ^'
1> No user-defined-conversion operator available, or
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Thanks =)
Eri523
October 12th, 2010, 07:41 PM
So, if i put String^ ja = "jaja" instead of String ja = "jaja" the error is:
[...]
Hmmm, I would have expected at least that to work, or using an implicitly dereferenced variable (i.e. String ja = "jaja";) and take its tracking handle using the % operator. And the error message you are getting for that puzzles me even more... :confused:
Maybe I'll have some better ideas after some hours of sleep or someone else comes along saying "aaah, that's simple!"... :D But for now I'm stuck too...
Zaccheus
October 13th, 2010, 11:32 AM
Have you tried:
String^ ja = gcnew String(L"jaja");
ListViewItem^ item1 = gcnew ListViewItem(ja);
listView1->Items->Add(item1);
Note the added ^ symbols.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.