BorisMatthews
asked on
VB.Net Bound Form set Read Only Dynamically
I have a VB.Net form bound to a DataSource via a TableAdaptor that displays information and depending upon the user logged in should be either enabled for edits or for other users read only.
On the load of the form I can quite easily set all the fields to be Enabled = False but this does not look good for the read only user.
Is there a way of making all controls (combo box, lisy box, text box etc) read only or is there a way of dynamically setting the bindingsource object to be read only?
On the load of the form I can quite easily set all the fields to be Enabled = False but this does not look good for the read only user.
Is there a way of making all controls (combo box, lisy box, text box etc) read only or is there a way of dynamically setting the bindingsource object to be read only?
ASKER
Are you saying that I can add this attribute to combo boxes and list boxes also?
I have implemented an interim solution whereby all text boxes have readonly set to True and then all combo boxes and list boxes have enabled set to false but this is not ideal.
I have implemented an interim solution whereby all text boxes have readonly set to True and then all combo boxes and list boxes have enabled set to false but this is not ideal.
Sorry, I'm so used to working with Web forms rather than Windows forms.
You have the solution for textboxes. List boxes are not editable by default. Comboboxes can be made to behave like DropDownLists where the items are select-able but not editable by setting the DropDownStyle.
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Does that cover it?
You have the solution for textboxes. List boxes are not editable by default. Comboboxes can be made to behave like DropDownLists where the items are select-able but not editable by setting the DropDownStyle.
Me.ComboBox1.DropDownStyle
Does that cover it?
ASKER
No this does not. Because the controls are bound to the data table if a read only user selects a new combo box or list box value this will be updated in the table...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is an AllowEdit property on bindingsource. Set it to false
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.allowedit.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.allowedit.aspx
ASKER
But that is in itself a read only property and has no Set procedure...
Oops. Are you using a datatable or dataset?
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/2535837a-9839-4825-a277-a851484d7826/
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/2535837a-9839-4825-a277-a851484d7826/
ASKER
I could not get the AllowEdit feature to stop the data being changed, not sur why as I followed the examples.
I have investigated further the suggestion to handle the click event and in fact for combo boxes I have created an event handler for all combo boxes on the form - their Enter event - and changed the focus to a text box that is read only.
This works well for combo boxes but could not get this to work for check boxes. The focus moved OK but this did not stop the check state of the checkbox changing...
I have investigated further the suggestion to handle the click event and in fact for combo boxes I have created an event handler for all combo boxes on the form - their Enter event - and changed the focus to a text box that is read only.
This works well for combo boxes but could not get this to work for check boxes. The focus moved OK but this did not stop the check state of the checkbox changing...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good idea to ensure no updates via trapping the update statement for a guest user which I have done. I have used a mix of suggestions from the answers given and so will share the points. The solutions works OK but is not ideal as really it would be good to have a visual way of showing the user that they are read only without having to disable some of the controls...
textBox1.Attributes.Add("r