Reputation: 1
I have an arraylist which stores values when a user does an action during runtime. Now im trying to display these values into a datagridview . so what im doing is adding the arraylist items into a datatable and then binding the datatable to the Gridview. but what is being displayed in the datagrid is not the values of the arraylist. here is my code .please help or can anyone direct me to how else this could be done..Thanks in advance
foreach (Class1 aa in ds)
{
checkedListBox1.Items.Add(aa.id + "_" + aa.shape + "_" + aa.color);
DataTable dt = new DataTable();
dt.Columns.Add("Shape");
dt.Columns.Add("Colour");
for (int i = 0; i < ds.Count; i++)
{
dt.Rows.Add(ds);
dt.Rows[i]["Shape"] = ds[i].ToString();
dt.Rows[i]["Colour"] = ds[i].ToString();
dataGridView1.DataSource = dt;
}
dataGridView1.Refresh();
}
}
Upvotes: 0
Views: 5044
Reputation: 3204
Maybe you can try creating a DataTable
and then adding the required DataRows
to it like this :
foreach (Class1 aa in ds)
{
checkedListBox1.Items.Add(aa.id + "_" + aa.shape + "_" + aa.color);
DataTable dt = new DataTable();
dt.Columns.Add("Shape");
dt.Columns.Add("Colour");
for (int i = 0; i < ds.Count; i++)
{
DataRow dRow = dt.NewRow();
dRow["Shape"] = aa.shape;
dRow["Colour"] = aa.color;
dt.Rows.Add(dRow);
}
dataGridView1.DataSource = dt;
dataGridView1.Refresh();
}
}
Hope this helps.
Upvotes: 1