How to handle Visibile when Read is not allowed

How to handle Visibile when Read is not allowed

Old forum URL: forums.lhotka.net/forums/t/3498.aspx


PAT336 posted on Friday, September 07, 2007

Hi,

I am trying to hide label and textbox when read is not allowed, as I don't want user to feel something is being hide on him. It does not seems like I can do automatically through calling ReadWriteAuthorization.ResetControlAuthorization.

Do I have to write extra lines on UI to check CanReadProperty and turn visibility on/off? Is there better way than writing code on UI whereever visibility need to be turn on/off? ReadWriteAuthorization class does not have any virtual methods that I can override. Am I missing something? Shouldn't framework handle visibility? I am confused, please help.

Thanks,

PAT

richardb replied on Monday, September 10, 2007

I'd say that's a User Interface decision, so while your business object tells you that the property cannot be read it's up to the person using your object to decide how they want to show that in whatever user interface they are writing.

You want to hide the control, and it's associated label so you'd need to do that in the UI.

Use of a base form might help so you can put some code in the base form to loop through the properties on your business object and hide the controls that are bound to properties that cannot be read, but would you know the associated label control that needs hiding also?

What if your controls are in a group box and every property is readonly.  Would you hide the groupbox too?  Difficult for your business object to tell you this - it would need to know about the UI and we don't want that.

 

 

PAT336 replied on Monday, September 10, 2007

Thanks Richard.

When I said framework is not handling visibility, I meant ReadWriteAuthorization class, not business class. I am thinking to modify this class to handle visibility. For label etc., I am thinking to create a custom property and bind with business property, and check if that property is implemented in control, to handle visibility. I am not sure if it will work as I am fairly new to .NET, I will give a shot.

Thanks

richardb replied on Monday, September 10, 2007

No problem - yes you could create your own version of the ReadWriteAuthorization or change it to how you want it to work.  I sometimes find that Windows Databinding is a minefield and quite tricky to delve into, but searching the internet often comes up trumps.

I, along with a colleague, did some forms visual inheritance with CSLA 1.5 a while back and at times we had fun trying to get the various data binding code in the base forms to work so it could cope with a BusinessBase, BusinessCollectionBases and so on.  We did it but at times wished we hadn't- too may "funnies".

Good luck - you've made a good start though using CSLA.  I think it's a fantastic framework.

Copyright (c) Marimer LLC