We help IT Professionals succeed at work.

WinForm Properties to disable Adding and Deleting records

I'm using VB.Net 2005 and I am trying to do the following on a WinForm;  When form loads, based on who is logged in, I want to enable or disable the user's ability to add and delete records.  The form has fields on the main form and also a datagridview.  I also need to be able to detect if the form is dirty (i.e. has records edited)

Question:
1.  What is the code to prevent adding/deleting records on main form and on the DataGridView?
2.  How do I determine if the Form is Dirty?
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
>> 1.  What is the code to prevent adding/deleting records on main form and on the DataGridView?
You can set the controls to readonly. In the DataGridView you can set to false the following properties AllowUserToAddRows, AllowUserToDeleteRows and readonly


>>2.  How do I determine if the Form is Dirty?
Don't understand this question

Author

Commented:
I'm basically trying to simulate some things in access which had a property .Dirty that got set to True if a particular record has been edited.

I do want people to be able to edit existing records, so my #1 above needs some sort of technique to detect if the pointer is on a new record or if the user is trying to delete an existing record.
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
Well DataGridView are bind to a dataset. When you change the bind datagridview you will be changing the dataset and you can check if the dataset as changes this way:

If MyDataSet.HasChanges Then
   MessageBox.Show("Datagridview changed!")
End If

Author

Commented:
Thank you.
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Glad I could help!

jpaulino

Explore More ContentExplore courses, solutions, and other research materials related to this topic.