I have a basic appalication that reads from a text file then splits string values values by comma and finally add this values to a gridview as rows.This my code to achieve this and its works.
using (StreamReader reader = new StreamReader(fileName))
{
string line;
while ((line = reader.ReadLine())!=null)
{
liste.Add(line.Split(',')[0]);
}
}
for (int i = 0; i < liste.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[1].Value = liste[i];
}
Gridview has two columns first one is checkbox and the other one is textbox column The problem is I need to get this row values from the gridview .But I am getting null pointer exception .So I have decided to check like this way
for (int i = 0; i < dataGridView1.RowCount; i++)
{
MessageBox.Show(dataGridView1.Rows[i].Cells[1].ToString());
}
and realized result are not as expected.Messagebox display this result
datagridviewtextboxcell {columnindex=1 rowindex=0}
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire