I have a little problem with iterating through a DataGridView.
Right now I have a textfile (just a long string: true;false;true etc.).
Now I want to read this file and set the value of my CheckBoxColumn in my DataGridView: First value in file = status of first CheckBoxCell Second Value in file = status of second CheckBoxCell and so on
There's no problem in parsing the string but I don't get how to iterate through the cells and set values.
Can anyone help?
Greetings
EDIT: Used OhBeWise's answer and do now have following code snippet:
private void Btn_LoadChampions_Click(object sender, EventArgs e)
{
string allChampionStates = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Open Text File";
openFileDialog1.Filter = "CSV|*.csv";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
allChampionStates = File.ReadAllText(openFileDialog1.FileName);
List<string> vals = allChampionStates.TrimEnd(';').Split(';').ToList();
int maxRows = Math.Min(this.dataGridView1.Rows.Count, vals.Count);
for (int i = 0; i < maxRows; i++)
{
DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[i].Cells["Status"];
cell.Value = vals[i] == "true";
}
}
}
But now it sets all checkbox values to false, even if there are only the first five false and all others are true. Any ideas?
EDIT 2: Simple mistake: I do save 'True' instead of 'true' :D Works like a charm. Thank you