I have a DataGridView that im trying to empty and then put data back into but no matter what method I try to fill the dgv I only get empty rows.
I have this code but no matter what I try, dt.Rows.Add(sortestStus[row])
always results in an empty row being added.
sortedStus = Split_List(stuRows);
DataTable dt = (DataTable)dgvClassStuInfo.DataSource;
dgvClassStuInfo.DataSource = dt;
dt.Clear();
for (int row = 0; row < sortedStus.Count; row++)
{
dt.Rows.Add(sortedStus[row]);
}
sortedStus
is a List<DataRow>
filled by a merge sort - this works as intended and sortedStus
is filled with rows that have their intended data. dt.Clear();
is working as intended and removing all rows but its the for loop that is causing issues.
I've tried dt.NewRow();
and adding each item individually but it still didn't work and I've also tried refreshing both the dgv and the datatable and that also didn't work. Anyone have any ideas?
ETA: sorry if this is a duplicate question but I can't seem to find any with this problem, only trying to actually add the empty rows.
ETA2: trying dt.Rows.Clear();
as Anonymous suggested has the same behaviour