Print Page | Close Window

populating and saving checklistbox data

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=802
Printed Date: 26-Apr-2026 at 11:47pm


Topic: populating and saving checklistbox data
Posted By: ShoshanahB
Subject: populating and saving checklistbox data
Date Posted: 08-May-2008 at 3:46pm

I am new to both DevForce and Winforms, and am stumped on what seems like a fairly simple operation. 

I have a checklistbox control that needs to display a set of Ethnicities, with the valid ethnicities for the selected person. The ethnicities available are stored in a business object called luEthnicity, and the list of valid ethnicities for the person is stored in another business object called buPerson_Ethnicity_Assignments.
 
I have created and populated two BindingSource objects to handle the business objects (bsEthnicities and bsAssignedEthnicities respectively).
 
I found that it is simple to display the available items by setting the checkboxlist's DataSource to bsEthnicities, and then identifying the DisplayMember and ValueMember.
 
Based on my google searches, it looks like I must manually populate and save the checkboxlist's selected values.
 
Before I start building a tool for this, I wanted to see if a) there is a cool tool or code example for these processes, and b) confirm that my general approach will work in the DevForce object model.
 
Here's what I think is needed:
  • On Page Load, loop through each buPerson_Ethnicity_Assignment for the selected person.  For each assigned ethnicity, use the  SetItemChecked function to check the corresponding value in the checkboxlist. 
  •  
  • When saving the page, loop through each checked item in the checkboxlist, and insert a new record into bsAssignedEthnicities for any newly selected ethnicities. 
 
Some questions:
1. Is there an easier way?  This seems like such a common activity, I'm suprised there isn't a code block somewhere.  Perhaps I've become spoiled by the DevForce binding managers.  :)
 
2.   When adding new assigned records, do I insert into the bsAssignedEthnicities, or add directly to the buPerson_Ethnicity_Assignments object?  If I go direct, could you direct me to a tutorial or documentation on how to do this?
 
thanks in advance for you help,
 
~ Shanah
 
 
 
 



Replies:
Posted By: davidklitzke
Date Posted: 09-May-2008 at 9:24am

I am not sure than I completely understand the problem.  I think I understand the Business Object for luEthnicity but, I really don’t understand what you mean by the list of valid ethnicities for the person.  Isn’t this just any one of the instances of the luEthnicity?  However, it seems like you may be suggesting that a person could belong to more than one Ethnicity.  This is fine, but while I may belong to Ethnicity A and E, Ethnicity A may be incompatible with Ethnicity B and I may belong to either Ethnicity A or Ethnicity B, but not both.

 

I’d also like to know how you are storing this information in the database.  For example does each Person object have a child collection of Assigned-Ethnicitiy objects.  Each Assigned-Ethnicity object has a foreign key reference to Person and a foreign key reference to Ethnicity.

 

Maybe an example would help,




Print Page | Close Window