Hi

Got a comboBox on a form where the user can add url favorites, When closing form using the following code.

// Create the XmlDocument.
			   XmlDocument^ doc = gcnew XmlDocument;
			   doc->LoadXml( "<item><name>Favorites</name></item>" );
			   
			   for(int i = 0; i < this->ComboBoxBM->Items->Count; i++)
			   {
				// Add a url.
				XmlElement^ newElem = doc->CreateElement( "url" );
			        String^ str = dynamic_cast<String^ >(this->ComboBoxBM->Items->default[i]);
			        newElem->InnerText = str;
			        doc->DocumentElement->AppendChild( newElem );
			   }

			   // Save the document to a file and auto-indent the output.
			   XmlTextWriter^ writer = gcnew XmlTextWriter( "favorites.xml", nullptr );
			   writer->Formatting = Formatting::Indented;
			   doc->Save( writer );

It save any default url's no problem, but will not save the user added url's to the comboBox. Tried this but keeps getting errors

String^ str = dynamic_cast<String^ >(this->ComboBoxBM->Items->Items[i]);


error C3293: 'Item': use 'default' to access the default property (indexer) for class 'System::Windows::Forms::ComboBox::ObjectCollection'

Any help would greatly appreciated

Finally found the solution, it can be found here I'll let you figure the rest out for yourself:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.