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

6 Years
Discussion Span
Last Post by ziggystarman
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.