Menu

How to get the list of checked items?

dicomduty
2015-12-15
2018-12-21
  • dicomduty

    dicomduty - 2015-12-15

    I want to get a list of the checked items. Does anyone have a code snippet, etc.

    This does not work: ListView.CheckedListViewItemCollection item = dataTreeListView.CheckedItems; Any clue would really be appreciated.

     
  • dicomduty

    dicomduty - 2015-12-15

    All the sample code I see allows you to check a row object. How does one get the entire list of checked objects? Surely someone knows how? Even a little hint may help.

     
  • Phillip Piper

    Phillip Piper - 2015-12-23

    It's very easy:

    var checkedObjects = olv.CheckedObjects;
    
     
  • Brian Buttolph

    Brian Buttolph - 2016-09-15

    When using a TreeListView with HierarchicalCheckboxes = true, CheckedObjects doesn't include child objects that were never made visible. How do you include the child objects in the list that have not been expanded in the tree by the user? (Once expanded, they are included.)

     
  • Brian Buttolph

    Brian Buttolph - 2016-09-16

    This works okay since there aren't many children below each root and they're only one-level deep. Maybe it's because I'm new to the control, but I couldn't figure out any other way. I'm open to suggestions on a different approach. Thanks.

    // kludge to ensure child objects that have never been 
    // expanded in the tree by the user are included in the list
    var roots = tvl.Roots;
    foreach (Object r in roots)
    {
        tvl.ToggleExpansion(r);
        tvl.ToggleExpansion(r);
    }
    IEnumerable<Fruit> e = tvl.CheckedObjects.OfType<Fruit>();
    
     
  • Brian Buttolph

    Brian Buttolph - 2016-10-25

    Unfortunately the kludge fails for objects that were never made visible in the control by the user and whose ancestor was unchecked. I have the ParentGetter working fine. It returns the correct parent object for the child. What am I missing? This is all very confusing.

     
  • Brian Buttolph

    Brian Buttolph - 2016-10-26

    Here's the fix I came up with. Area is the parent that each Fruit has a reference to. Note that the kludge above must run before this.

    IEnumerable<Fruit> sel =  tvl.CheckedObjectsEnumerable.OfType<Fruit>();
    IEnumerable<Fruit> query = from f in sel
        where (tvl.IsChecked(f.Area) || tvl.IsCheckedIndeterminate(f.Area))
        select f;
    foreach (Fruit fruit in query)
    ...
    
     
  • Tom Strickland

    Tom Strickland - 2018-12-21

    Totally cheesy but simple solution is to call ExpandAll() right before calling CheckedObjects. In my case I'm using TreeListView in a dialog box and only need to enumerate CheckedObjects after the dialog closes so the expand is hidden from view.

    I definitely need to circle back and implement something more elegant later but this will work for now.

    Tom

     

Log in to post a comment.

MongoDB Logo MongoDB