I am not sure what data type BD
is, but I have to assume it is an indexable list (i.e. it has a this[int]
property, and either a Count
, GetUpperBound()
, or Length
property). Otherwise the question "can I do it in reverse order?" is a meaningless question, because you would be working with a list with indeterminate order which would also have an indeterminate reverse order.
So, given that it is indexable, you simply need to use a for
loop instead of foreach
.
for (int i = bd.NameList.Count-1; i>=0; i--)
{
var bData = bd.NameList[i];
Object[] param = new Object[2];
param[0] = bData.m_Width;
param[1] = bData.m_Height;
DataGrid1.Rows.Insert(0, param);
}
Or... if you love the enumerator... just use Add(X)
instead of Insert(0, X)
, which will append to the end of the list. Obviously this will only work if you are adding to a DataGridViewRowCollection
and may not work in other situations.
foreach (BD bData in bl.NameList)
{
Object[] param = new Object[2];
param[0] = bData.m_Width;
param[1] = bData.m_Height;
DataGrid1.Rows.Add(param);
}