private ListViewItem createListItemByClass(DrugClass drug) { ListViewItem item = new ListViewItem(); item.SubItems.Clear(); item.SubItems[0].Text = drug.DrugName; item.SubItems.Add(drug.DrugID); item.SubItems.Add(drug.Price.ToString()); item.SubItems.Add(drug.Creation); return(item); }
private void button3_Click(object sender, EventArgs e) { list = new List <DrugClass>(); foreach (ListViewItem item in listView1.Items) { DrugClass drugObj = new DrugClass(); drugObj.DrugName = item.SubItems[0].Text; drugObj.DrugID = item.SubItems[1].Text; drugObj.Price = Convert.ToInt32(item.SubItems[2].Text); drugObj.Creation = item.SubItems[3].Text; list.Add(drugObj); } //DrugsClass drugs = new DrugsClass(); //drugs.Drugs = list; XmlSerializer.SaveToXml(fileName, list, typeof(List <DrugClass>)); //System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.OpenOrCreate); //System.Runtime.Serialization.DataContractSerializer sr = new System.Runtime.Serialization.DataContractSerializer(drugs.GetType()); //sr.WriteObject(fs, drugs); //fs.Close(); }