Question

I have a dropdown in my toolstrip (toolbar) i have attached a click event to each item in drop down as the dropdown has been populated dynamically, now i can casted the selected item in the dropdown and set its state to checked, to have a tick next to it, i wish to have a loop in another method to check which item has been checked. How do i loop through the items in the dropdown checking which item is checked?

  foreach (DataSet1.xspLibraryByNameRow libName in data.xspLibraryByName)
        {
            var name = new LibraryItems(libName);
            if (libName.xlib_Code != "NULL")
            {
                catDrpDwn.DropDown.Items.Add(name);
                catDrpDwn.DropDown.Tag = name;
                name.Click += new EventHandler(name_Click);
            }
        }

    }

    void mapArea_VE_MapReady(object sender, EventArgs e)
    {
        loadPoints();
    }

    void name_Click(object sender, EventArgs e)
    {
        var selected = (LibraryItems)sender;
        selected.Checked = true;

        loadPoints();
    }
Was it helpful?

Solution

        foreach (var items in catDrpDwn.DropDown.Items)
        {
            var it = (LibraryItems)items;
            if (it.Checked == true)
            {

            }
        }

OTHER TIPS

Try this

var items=catDrpDwn.DropDown.Items.Cast<LibraryItems>().Where(d=>d.Checked).ToList();

here you will get all checked items and you can loop into it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top