1
Answer

Edit selected item of datagridview and .txt file as well

Ask a question
Hi, friends i want to edit contact in my phone directory application using datagrid, textbox and a button
please help me !!

and my second question is about deleting I had completed deleting process but some time it doesn't work correctly!
  !!here is the code!!
 
       
 
private void button2_Click(object sender, EventArgs e)
{
List<string> myList = File.ReadAllLines("contact.txt").ToList(); //read
foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
try
{
DialogResult result = MessageBox.Show("are you sure to delete!!", "Warning!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
myList.RemoveAt(item.Index);
File.WriteAllLines("contact.txt", myList.ToArray());
dataGridView1.Rows.RemoveAt(item.Index);
}
else
{
this.dataGridView1.Focus();
}
}
catch
{
MessageBox.Show("unable to delete", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
 

Answers (1)