CheckedListbox Displaymember and ValueMember

Frank Fischer picture Frank Fischer · Nov 15, 2012 · Viewed 17.1k times · Source

I have some problem with my Checked List Box.

public void GetFolder()
    { 
         var dict = new Dictionary<string, string>();
         foreach (Folder folder in rootfolder.FindFolders(new FolderView(100)))
            {
             dict.Add(folder.Id.ToString(),folder.DisplayName);
            }        

       checkedListBox1.DataSource = new BindingSource(dict, null);
       checkedListBox1.DisplayMember = "Value";
       checkedListBox1.ValueMember = "Key";

    }

And now i want do get all Checked List boxes,

I do this with

         foreach (object item in checkedListBox1.CheckedItems)
        {
            lala = lala + item +"|";

        }

My CheckedListbox shows me the CheckIcon and the Name of all Folders that i read from Directory, and i want now to store tie folder.Id in some Settings but only the ID but i´m getting allways Foldername and ID together.

Hope Someone can help me maybe i have some tomatoes on my eyes :)

Answer

TheGeekZn picture TheGeekZn · Nov 15, 2012
public void GetFolder()
    { 
         var dict = new Dictionary<string, string>();
         ArrayList arr = new ArrayList();
         foreach (Folder folder in rootfolder.FindFolders(new FolderView(100)))
            {
             dict.Add(folder.Id.ToString(),folder.DisplayName);
             arr.Add(folder.Id.ToString());
            }        

       checkedListBox1.DataSource = new BindingSource(dict, null);
       checkedListBox1.DisplayMember = "Value";
       checkedListBox1.ValueMember = "Key";

       //Do whatever to arraylist..
    }

This will give you an array list with all the ID's in it. You could bind that to a source, or run a foreach loop to get all the items.