'How to add new rows to the top in datagrid view
I have a DataGridView in which Im adding row values in runtime. Each new row is added below the previous row. I want to add newest row on top. When a new row is added I want the previous row to be below the new one.
I also need some help in deleting the oldest row once the row count reaches 100, so that my DGV will always have 100 rows no matter how many rows I add. I tried this by doing this, but it always gives me an index out of range error:
if (dataGridView4.Rows.Count >= 99)
{
dataGridView4.Rows.RemoveAt(0); //also tried 98
}
Solution 1:[1]
you can bind your DataGridView
with source collection .Try adding new item by inserting item in source such as this code
datalist.Insert(0, item)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohammad Asgharian |