String into Listbox from Linked List...

cant pass a string into a listbox from a linked list

Page 1 of 1

2 Replies - 3243 Views - Last Post: 30 March 2007 - 08:57 PM Rate Topic: -----

#1 brandonb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-March 07

String into Listbox from Linked List...

Posted 27 March 2007 - 01:35 AM

I've recently been converting a program me and my friend made that uses a forward linked list (backwards is also planned), but the main problem is that I have gotten stuck in converting it into a GUI app (CLR Windows Form Application) and now when I try to read information from my sortedlist to a listbox it gives me:

error C2664: 'System::String::Insert' : cannot convert parameter 2 from 'std::string' to 'System::String ^'

What I have done is created a linked list and have it created at program load.
Then I have functions set up in a class List

(function set in stdafx.h)
//stdafx.cpp
string List::test()
{
	return(head->lname);
}



When I changed test() to be a bool and return head->deleted and use this insert method, it would place "True" or "False" at the top of the list, but when I try to pass a string, it gives me that weird error...

List l;
this->listBox1->Items->Insert(0, l.test());
(this wont work with strings because it's looking for System::Object?)

In attempt to insert a string I try:
this->listBox1->Text->Insert(0, l.test());

...and this is where I get the error pasted at the top of this.

Well, If anyone knows how to just get the information from my linked list into the listbox then I can handle changing back and forth from items. All I really need is help getting it to actually list it (unless there's a better place to put it...).

Thanks,
Brandon

(The program is attached if you would like the code)

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: String into Listbox from Linked List...

#2 brandonb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-March 07

Re: String into Listbox from Linked List...

Posted 30 March 2007 - 03:31 PM

Answered my own question so I thought it'd be good to have the results...

By using : I can convert from a System ^ string to string
// converts a previous string named x
char* fname = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(x).ToPointer();
string str(fname);



By using : I can convert from a string to System ^ string
// converts a previous string named x
String ^ fname = gcnew String(x.c_str());



By using : I can convert a System string to wstring (used mainly in forms...)
// converts a previous string named x
pin_ptr<const wchar_t> wch = PtrToStringChars(x);
wstring fname(wch);
fname += L" (basic_string)";



Hopefully this helps someone else fix their program faster if they run into the string problem....
(Nodes can't hold System^ strings...)

Thanks
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: String into Listbox from Linked List...

Posted 30 March 2007 - 08:57 PM

I am glad that you posted the answer. I am not a >NET guy and so I really didn't know where to go on that question.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1