New Posts New Posts RSS Feed: Best way to check only one checkbox in datagrid
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Best way to check only one checkbox in datagrid

 Post Reply Post Reply
Author
owais,zahid View Drop Down
Newbie
Newbie
Avatar

Joined: 22-Aug-2007
Location: Pakistan
Posts: 8
Post Options Post Options   Quote owais,zahid Quote  Post ReplyReply Direct Link To This Post Topic: Best way to check only one checkbox in datagrid
    Posted: 22-Aug-2007 at 7:46am
Well the simplist way to implement this will be with the help of verifiers. Suppose u have an entity of Employee which has a field of "Primary Credit Card". Now there is another businees object of Credit Card, which contains the list of credit cards. Now, only one credit card from the list will be in Employee Primary Credit Card. So, we can add two verifiers in Employee class
 
1) Verify that Primary Credit Card is not null entity.
2) Verify that only one Credit Card can be primary card.
 
Now, How will you gonna do it.
1) Binding the grid with credit card objects.
2) Catch the event of cell change and validate the parent Employee by calling Verift.
 
Hope this will help.
Back to Top
Miszou View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 19
Post Options Post Options   Quote Miszou Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2007 at 11:41am

One of my business objects has a "primary" boolean property. There can be several of these objects, but only one of them can be marked as the primary entity, and there must always be one and only one primary entity.

In my datagrid, I have mapped this property to a checkbox, so that each row in the datagrid shows a text field and a checkbox. A contrived example is shown below:
 
Property        IsPrimary
Pontiac            [ ]
Ford               [x]
Toyota             [ ]
Nissan             [ ]
 
There should always be one and only one primary item selected, which means that checking the box for "Ford" should have no effect, because unchecking the box would be an invalid selection and checking any other item should uncheck "Ford".
 
Now, in trying to separate the business logic from the user interface, what would be the best/easiest way to implement this? I have tried messing with the "IsPrimary" property on the object, to uncheck all others if a new one is checked, and it appears to work ok... it just doesn't feel "right" somehow.
 
Also, the business object does not appear able to prevent a checked item from becoming unchecked - yet the UI does not know this is not allowed...
 
Should I just implement this in the UI, or is there a better way?
 
Thanks!
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down