禁用在以前的记录上编辑但在数据表中添加新记录 [英] Disabling Editing on previous records but Adding new Records in data table
本文介绍了禁用在以前的记录上编辑但在数据表中添加新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为POdatagridview的现有数据表。它与SQL Server数据库中的表绑定。我想要发生的是禁用我前端的先前记录的编辑,但我可以在数据表中添加新记录。
我尝试通过属性禁用编辑但是,我无法添加新记录。
I have an existing data table called POdatagridview. It is bound with a table in the SQL Server database. What I want to happen is to disable editing of the previous records in my front-end but I can able to add new records in the data table.
I tried disabling edit via Properties but, I couldn't add new records.
Private Sub PODataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles POdDataGridView.CellContentClick
Me.PODataGridView.AllowUserToAddRows = True
End Sub
请帮助。非电脑专业。 :)
Please Help. Non-computer major here. :)
推荐答案
检查当前行的主键值。如果要添加新记录,则将主键值设置为-1,否则将在数据表中填充原始主键值。因此,在编辑时检查当前行的主键值是否为-1。如果为-1则允许编辑。否则禁用编辑。
Check for the Primary key value of the current row. If you are adding a new record then make the primary key value to -1 else original primary key value will be populated in the datatable. So while editing check if the primary key value for the current row is -1 or not. If -1 then allow editing. Else disable editing.
这篇关于禁用在以前的记录上编辑但在数据表中添加新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文