//---create a sortedlist.... static SortedList^ inventory = gcnew SortedList(); private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { // and fill with some products inventory->Add("Golf balls", 29.50); inventory->Add("Shirts", 49.95); inventory->Add("Putters", 39.49); inventory->Add("Tees", 2.50); inventory->Add("Shoes", 59.50); inventory->Add("Hats", 14.50); inventory->Add("Pull Carts", 129.50); UpdateGrid(); //display data in grid } private:System::Void UpdateGrid() { //---clear grid to avoid duplicates dgvProducts->Rows->Clear(); dgvProducts->Refresh(); //---fill the grid. Be sure to look at the columns property then defaultcellstyle to align them to the right for each(KeyValuePair products in inventory) dgvProducts->Rows->Add(products.Key, products.Value.ToString("n2")); } private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e) { if(txtNewItem->Text->Trim() == "" | txtNewPrice->Text->Trim() == "") NotifyUser("Please enter new item and price"); else { String^ newItem = txtNewItem->Text->Trim(); double newprice = Convert::ToDouble(txtNewPrice->Text->Trim()); inventory->Add(newItem, newprice); //add to the sortedlist UpdateGrid(); } } private:System::Void NotifyUser(String^ msg) { MessageBox::Show(msg, "Working with SortedLists", MessageBoxButtons::OK, MessageBoxIcon::Error); } private: System::Void btnRefresh_Click(System::Object^ sender, System::EventArgs^ e) { UpdateGrid(); }