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 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);
}
}
}
ali tuncerPosted Apr 16, 2016, 11:51 PM
{
if (dataGridView1.SelectedRows.Count > 0)
{
//delete code here
}
else
{
//MessageBox.Show("no row selected to delete")
}
}
{
List
string editLine = myList[e.RowIndex].ToString();
string newValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
string[] con = editLine.Split(',');
string oldValue = con[e.ColumnIndex].ToString();
myList.RemoveAt(e.RowIndex);
myList.Insert(e.RowIndex, editLine.Replace(oldValue, newValue));
File.WriteAllLines("contact.txt", myList.ToArray());
}