I want to show the Insertion Row in the DataGridView at the top of the grid. How can I do this using C# or VB.NET ?
C#Visual Basic.NET
Last Comment
rajesh_khater
8/22/2022 - Mon
cheddar73
I don't think this can be done. The DataGridView control has a NewRowIndex property that returns the Index within the Rows collection of the insertion row, but unfortunately that property is ReadOnly.
You can, however, automatically scroll down to make the insertion row visible with the line:
Is it not possible to show the insertion row or new row as always the first row in the grid ?
I heard DataGridView is extensively customizable and you can override almost all its behaviours by writing a custom class and overriding appropriate methods of the base class.
Priest04
I don't see what exactly has mislead you in my post?
I am talking about the default visibilty of the "new" row, which is at the bottom of the grid, where the user types "new" values. You are talking about adding a row programmatically at a given index !!
Do you mean I can have bound data in all the rows, and still keep the first row as unbound containing no data ?
Then after the user moves out of the last cell in this simulated new row, how do I put the newly entered values at the end of the grid ? And how do I create a fresh "simulated" new row ?
rajesh_khater
ASKER
Can you give some detailed code example ? Your approach sounds interesting .
Maybe it can be done with bound mode too, but moving added row at the bottom will need to be done on DataTable object. Also, you would need to set AllowUserToAddRows to False
Goran
rajesh_khater
ASKER
Pls leave this open for some more time, as I was busy and could not try out the solution.
You can, however, automatically scroll down to make the insertion row visible with the line:
DataGridView1.FirstDisplay