Adding items to ListBox

  • Thread starter Thread starter sach
  • Start date Start date
S

sach

Hi,

Please help me in adding Items to ListBox control on runtime.

Whenever I try to add strings to items it gives me Error
"error C2664: 'System::Windows::Forms::ListBox::ObjectCollection::Add' :
cannot convert parameter 1 from 'std::string' to 'System::Object __gc *'

Can someone help.. how to overcome this ?

Thanx
 
sach said:
Hi,

Please help me in adding Items to ListBox control on runtime.

Whenever I try to add strings to items it gives me Error
"error C2664: 'System::Windows::Forms::ListBox::ObjectCollection::Add' :
cannot convert parameter 1 from 'std::string' to 'System::Object __gc *'

Can someone help.. how to overcome this ?

Thanx
Try this:
std::string yourSTLstring;
String *s = Convert::ToString(yourSTLstring.c_str());
listbox->Add(s);
std::string does not inherits from Object * managed object. You only can
add Object * or childs of this class.

--
Jacobo Rodríguez Villar

Proyectos en desarrollo:

http://www.typhoonlabs.com
 
Thanks Jacobo
It works great..

Also, can I have data-value pair added to list box..
something like
Data is USA, UK etc. and corresponding values be 1,2 . and so on..

Thanks
 
sach said:
Thanks Jacobo
It works great..

Also, can I have data-value pair added to list box..
something like
Data is USA, UK etc. and corresponding values be 1,2 . and so on..

Thanks
All item inserted into a listbox have an index assotiated in the order
ithat you had inserted.
see the documentation of SelectedIndex and SelectedItem. :)

--
Jacobo Rodríguez Villar

Proyectos en desarrollo:

http://www.typhoonlabs.com
 
Yeah, I know that but the problem is that my values associated with display
data are not same as index..
Is there any something like DisplayValue and DataValue.

I did that in VB.NET but is not aware how to do that in VC++.NET

Please suggest.
Thanks
 
Back
Top