Click to See Complete Forum and Search --> : small checklistbox problem


nightscorpion
June 30th, 2009, 06:26 PM
Hello Guys ,
i have a small problem here with my list . i display only an EA.Element names in my checklist box . When a user selects a name of the BC i would like to pass the whole element as a parameter to my event handler and i do not have much idea how this work. Would be really gratefull for any help


case "includedinBC":
list = new ArrayList();
ArrayList BClist;
BClist = utility.getBCollUCs(repo); // get all Business Collaborations
list = utility.getIncludedBC(element, repo); // Get included BC
foreach (object o in BClist)
{
EA.Element Bcollaboration = (EA.Element)o;
checkListBox.Items.Add(Bcollaboration.Name);

}
for (int i = 0; i < BClist.Count; i++)
{
EA.Element bcoll = (EA.Element)BClist[i];
for (int j = 0; j < list.Count; j++)
{
EA.Element client = (EA.Element)list[j];

if (client.Name.Equals(bcoll.Name))
{
checkListBox.SetItemChecked(i, true);

}
}
// include a BC which is not included
checkListBox.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
}


break;


here is my event handler

private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
{
CheckedListBox checklistBox = (CheckedListBox)sender;
String includedBC = (String)checklistBox.SelectedItem;
// i would like to get the EA.Element of the Selected Item....!!!?????

}

JonnyPoet
July 2nd, 2009, 05:02 AM
Your code needs to be in 'code' tags not in 'quote' tags. The difference is that in quote Tags it looses formatting, while in code tags it doesn't loose format. So please change this and correct format of code so its readable, because when I try to answer I cannot access the codesegment on my editor - if it would be in codetags Answering people are able to access that code.
CodeTags are quite similar to quote tags only change the word 'quote ' and use 'Code' there in the tags.

Basically you problem is when you load the list with strings only you only can access strings. If ou load them with a class you can access that class again as selected Item. But be sure that you override the ToString() method of your class so the listbox will show the wanted result. Because when you add classes to a list then the list shows the TOString() result on the screen as the listItem