ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo ^'
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo ^'

  1. #1
    Join Date
    Sep 2010
    Posts
    35

    ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo ^'

    Hi all.
    Im having a problem when i make my program.
    The code is:
    Code:
    string ja = "jaja";
    ListViewItem item1 = gcnew ListViewItem(ja,0 );
               listView1->Items->Add(item1);
    And it gives me the following error:
    Code:
    : 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

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    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:

    Code:
    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
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Sep 2010
    Posts
    35

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    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

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    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...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Sep 2010
    Posts
    35

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    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
    Code:
    private: System::Windows::Forms::ListView^  listView1;
    Then i inizialize
    Code:
    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:
    Code:
    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:
    Code:
    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:

    Code:
    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 =)

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    Quote Originally Posted by krosty4782 View Post
    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 &#37; operator. And the error message you are getting for that puzzles me even more...

    Maybe I'll have some better ideas after some hours of sleep or someone else comes along saying "aaah, that's simple!"... But for now I'm stuck too...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: ERROR - from 'std::string' to 'System::Runtime::Serialization::SerializationInfo

    Have you tried:

    Code:
    String^ ja = gcnew String(L"jaja");
    ListViewItem^ item1 = gcnew ListViewItem(ja);
    listView1->Items->Add(item1);
    Note the added ^ symbols.
    Last edited by Zaccheus; October 13th, 2010 at 11:34 AM.
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center