简体   繁体   中英

Moving a row to the top of an unbound datagridview

I have a form created which an unbound datagridview that has three columns. "Position", "ID", "Name". The data is being added at runtime into a database upon the forms completion. (I don't want to add unnecessary rows to the database in the event a person clicks Cancel.)

What I need to do is on the deletion of a row in the datagridview, search through the rows "Position" for a "HJ" value. If it's not found, change the "Position" value of the first row to be "HJ".

Here's a photo of what I mean:

屏幕截图

I've already taken care of the "Add Judge" button. The "Make Head Judge" button I guess will be on another question.

EDIT: Code removed, not needed since I found a function to search through a datagridview for me.

I found information about FirstDisplayedScrollingRowIndex but I can't seem to get it to work for some reason. Any assistance is greatly appreciated.

I would add a hidden column "rank" which could be used to sort the grid. Enumerate each of your ranks: HeadJudge = 0, AsstHeadJudge = 1, Judge = 2. If you will only have one head judge, then sorting by rank will always place the HeadJudge in the first row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM