Multi-dimensional ArrayList to ListBox with values

D

Dan

I'm trying to create a listbox that displays a list of user names, and has a
value (not displayed) of the users DN. I'm querying LDAP for the info, and
if I just populate the listbox directly with the text/value pair, it works
PERFECTLY.

lstGAL2.Items.Add(new
ListItem(entryResult2.Properties["displayName"].Value.ToString() + "(" +
entryResult2.Properties["mail"].Value.ToString() + ")",

//entryResult2.Properties["distinguishedName"].Value.ToString()));

Unfortunately I need to sort the data, so I'm modifying the code to write
the username and DN to an ArrayList first. Then I sort the list, and then
set the ListBox.DataSource = the ArrayList.

ArrayList list = new ArrayList();
....
list.Add(new
ListItem(entryResult2.Properties["displayName"].Value.ToString() + "(" +
entryResult2.Properties["mail"].Value.ToString() + ")",

entryResult2.Properties["distinguishedName"].Value.ToString()));

I used to be able to access the value by looking at the SelectedValue of my
listbox, but now that doesn't work.

search.Filter = ("(distinguishedName=" + ListBox.SelectedValue.ToString() +
")");

When I look at the contents of the ArrayList when I set it as the listbox's
data source, it has the values in it. I'm VERY new to this (sorry), and
can't figure out how to be able to pull the values from the listbox now (if
they get copied over in the first place. If I try to query for the
selectedValue, I just get the user name (selected text.)

Any hints as to what I'm doing wrong are GREATLY appreciated. Like I said,
I'm new to this (and am reading quite a few books, and trying a LOT of code
out to fix that), so a little extra explination in your answer is
appreciated.

THANKS!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top