I'm sorry, my code was slightly incorrect before, hopefully this should be self explainitory..
- int count = 0;
-
int[] n = new int[chlistDomains.Items.Count];
-
int trackPos = 0;
-
string[] s = new string[chlistDomains.Items.Count];
-
-
for (int i = 0; i < chlistDomains.Items.Count; i++)
-
{
-
if (chlistDomains.Items[i].Selected)
-
{
-
count++;
-
n[i] = trackPos;
-
s[i] = chlistDomains.Items[i].Value;
-
}
-
trackPos++;
-
}
-
-
-
int listPos = 0;
-
foreach (string item in s)
-
{
-
if (clistPrefferedEmployement.Items[n[listPos]].Value == item)
-
{
-
clistPrefferedEmployement.Items[n[listPos]].Selected = true;
-
}
-
listPos++;
-
}
I have made assumptions based on your original post, I hope they are correct:
- the items in chlistDomains and clistPrefferedEmployement are the same and in the same order.
- the items are already in the clistPrefferedEmployement list prior to the event.
(if not, you could always add the items into clistPrefferedEmployement) just replace the foreach statement with:
- int listPos = 0;
-
foreach (string item in s)
-
{
-
clistPrefferedEmployement.Items.Add(item);
-
}
Hope this is clearer than my first answer?