Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CheckedListbox Displaymember and ValueMember

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 :)

like image 981
Frank Fischer Avatar asked Oct 05 '22 23:10

Frank Fischer


2 Answers

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.

like image 159
TheGeekZn Avatar answered Oct 12 '22 20:10

TheGeekZn


I'm asuming lala is your settings string.

If that is the case, use this:

lala = lala + item.Value.ToString() +"|";

This way, lala woud contain all the IDs like this: 1|2|34|567|5...

like image 38
Kiro Coneski Avatar answered Oct 12 '22 20:10

Kiro Coneski