* Create a new windows applicaiton project & add a new form
* Add controls textBox1,comboBox1,btnAdd (button),brnBrowse,btnRemove,btnRemove
* Add
using System.IO;
*try the following code, you can type in a string in the text box and click btnAdd and see the data is in the combo box, you can close the applicaion and open it the data will be still there -- hope this helps
public partial class Form1 : Form
{
public readonly string xsdPath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData), "url.xsd");
public readonly string xmlPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "url.xml");
private DataSet ds;
public Form1()
{
InitializeComponent();
}
private void LoadDataset(){
try
{
if (File.Exists(xsdPath))
{
ds = new DataSet();
ds.ReadXmlSchema(xsdPath);
}
else
CreateSchema();
if (File.Exists(xmlPath))
ds.ReadXml(xmlPath, XmlReadMode.IgnoreSchema);
}
catch (Exception ex) { throw ex; }
}
private void CreateSchema()
{
try{
ds = new DataSet("dUrl");
var tUrl = ds.Tables.Add();
tUrl.Columns.Add("Url",typeof(string));
}
catch (Exception ex) { throw ex; }
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
LoadDataset();
RefreshData();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void RefreshData()
{
try
{
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "Url";
}
catch (Exception ex) { throw ex; }
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ds.WriteXml(xmlPath, XmlWriteMode.DiffGram);
}
private void btnAdd_Click_1(object sender, EventArgs e)
{
try
{
if (textBox1.Text.Trim().Length != 0)
{
ds.Tables[0].Rows.Add(textBox1.Text);
}
RefreshData();
textBox1.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows[comboBox1.SelectedIndex].Delete();
}
}