I have 2 forms. First form contains the datagridview and on the second form the users can change a single value in the datagridview in first form. The problem is if the user changes a value, the same value in other cells are changed too.
Ex) Before:
A B B C D
B B C D E
After(If I would try to change only one B after A to Z, it will change all Bs):
A Z Z C D
Z Z C D E
Form 1:
private void callForm2(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
f2.Text = this.dataGridView1.CurrentCell.Value.ToString();
}
Form 2:
private void button1_Click(object sender, EventArgs e)
{
string edit = File.ReadAllText(@"C:\Master.txt");
edit = edit.Replace(Text, textBox1.Text); //first Text = old value, textBox1 = new value
File.WriteAllText(@"C:\Master.txt", edit);
string message = "Item is modified on the list!";
string caption = "Success";
MessageBoxButtons button = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Information;
MessageBox.Show(message, caption, button, icon);
this.Close();
//Changes Successfully, but if the cell value is same it changes all the same values
}
The Form 1 gets the data from a text file
private void button1_Click(object sender, EventArgs e) //Add txt to program
{
if (File.Exists(@"C:\Master.txt")) //Look fot txt
{
using (StreamReader master = File.OpenText(@"C:\Master.txt")) //txt to table
{
int row = 0;
string s = String.Empty;
while ((s = master.ReadLine()) != null)
{
string[] columns = s.Split(',');
dataGridView1.Rows.Add();
for (int i = 0; i < columns.Length; i++)
{
dataGridView1[i, row].Value = columns[i];
}
row++;
}
}
}
else
{
string message = "Program was not able to find the text file.";
string caption = "Failed";
MessageBoxButtons button = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Warning;
MessageBox.Show(message,caption,button,icon);
}
}