简体   繁体   中英

Prevent new row in DataGridView

I have a DGV that has two columns where one of the columns is read only. The other column the user can makes edits in.

I have it coded with a predetermined number of rows(8). I have set the property "Enable Adding" of new rows to false. Setting this property to False makes the last row not visible.

All is good. Or is it? Meaning, if I arrow down through the rows, once my cursor reaches the last row of the DGV, a new "row" is added to the DGV. I want to prevent this occurrence.

Setting "Enable Adding" does not completely disable adding of new rows (?).

There is a property on the System.Windows.Forms.DataGridView.AllowUserToAddRows, set it to false. Hope it helps.

在设计器上启用添加属性

The DataGridView height size in pixels needs to be at least 2 pixels greater than the total height of all the rows and the header row combined if you want the rows to fit perfectly in the DGV without any white space at the bottom of the DGV. Setting the heights to be equal (DGV height size = summation of all row heights + columnheader height) will not work. What happens there is what was described in the original post. You tab down through the rows and when the cursor enters the last row, white space is added at the bottom of the DGV. This looks like another row but is just white space added to the DGV.

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