简体   繁体   中英

How to control primary key in datagridview with c#

I am developing window c# application. I have data entry grid view and binding data with data table. The table from SQL database has primary key. In grid view, the primary key is working in behind. I used DefaultValuesNeeded event for primary key. It is okay. But it is not okay when I click on cell of new row or grid view combo and input some value in some cell and delete that value. And when I move the cursor to another row, the new row in grid view is disappeared but in behind, the primary key is null and getting error primary key can't insert null into the table. So help me please how to control primary key in grid view when I direct access to grid view. Thanks you. PS I don't want to use text box or combo box and add button to add data row to grid view and I want to play mouse cursor in grid view whatever I want. I want to direct input entry to grid view. Thanks again.

将网格视图与主键绑定为第一隐藏列,每当您尝试更新时,删除操作都会记录传递隐藏列的值,如果删除,则在DML操作成功后删除该网格视图的行

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