Avatar of rajesh_khater
rajesh_khater
 asked on

Showing Insertion row in DataGridView at the top

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

Avatar of undefined
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:

DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.NewRowIndex
ASKER CERTIFIED SOLUTION
Priest04

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rajesh_khater

ASKER
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?

Goran
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
rajesh_khater

ASKER
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 !!

SOLUTION
Priest04

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rajesh_khater

ASKER
>> you would need to leave first row blank

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 .
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Priest04

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Priest04

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.