I have a BusinessBaseList bound to a Grid control, one of the columns is a check box. Only one row can can have a tick in the checkbox, so if a user puts a tick in another row, the previous checked row must have the value removed.
I have currently got this working by looping around the row collection of the grid and setting all rows other then the newly checked to unchecked.
Although this is working, our next stage is to create a web front end as well as the windows version.
So we really need this logic in the business object, what would be the best way to achieve this?
Thanks
The easiest way is probably a business rule. In the rule
check the new value, and if it is try, loop through all other rows in parent
list and set them to false( if they are true).
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: AndyW
[mailto:cslanet@lhotka.net]
Sent: Monday, October 27, 2008 10:58 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Adding logic to Business Object
I have a BusinessBaseList bound to a Grid control, one of the columns is a
check box. Only one row can can have a tick in the checkbox, so if a
user puts a tick in another row, the previous checked row must have the value
removed.
I have currently got this working by looping around the row collection of
the grid and setting all rows other then the newly checked to unchecked.
Although this is working, our next stage is to create a web front end as
well as the windows version.
So we really need this logic in the business object, what would be the best
way to achieve this?
Thanks
Thanks Sergey,
I have it working in most part, but I do not know how to get the value of the child object that has changed.
For instance everytime a checkbox is clicked the Custom Rule is fired and sets all the checkboxes to false, however I am unsure of how to ignore the child row that has changed.
Here is my custom validation rule that is set in the parent object.
private static bool IsHomepageCheck<T>(T target, Csla.Validation.RuleArgs e) where T : Article return true;
}
As you can see I am setting all the items to false, but I need to ignore the item that has been changed.
Thanks
Andy
I think you would need the Equals check and move the rule to
articleImage level
private static bool IsHomepageCheck<T>(T target,
Csla.Validation.RuleArgs e) where T : ArticleImage
{
foreach (ArticleImage artImg in
(ArticleImageList)target.Parent))
{
If (!(artImg.Equals(target)
&& artImg.IsHomepage == true)
artImg.IsHomepage
= false;
}
return true;
}
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: AndyW
[mailto:cslanet@lhotka.net]
Sent: Tuesday, November 11, 2008 8:09 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Adding logic to Business Object
Thanks Sergey,
I have it working in most part, but I do not know how to get the value of
the child object that has changed.
For instance everytime a checkbox is clicked the Custom Rule is fired and
sets all the checkboxes to false, however I am unsure of how to ignore the
child row that has changed.
Here is my custom validation rule that is set in the parent object.
private static bool IsHomepageCheck<T>(T target,
Csla.Validation.RuleArgs e) where T : Article
{
foreach (ArticleImage artImg in
target._articleImages)
{
artImg.IsHomepage
= false;
}
return true;
}
As you can see I am setting all the items to
false, but I need to ignore the item that has been changed.
Thanks
Andy
Thanks Sergey, all is now working, much appreciated :-)
I could be wrong, but I see potential problems with that implementation if you were ever to call check rules manually on an object in the child list. It looks like it would unconditionally set any existing IsHomePage value in the list that was true to false.
Copyright (c) Marimer LLC