{"id":2278,"date":"2022-08-30T15:23:32","date_gmt":"2022-08-30T15:23:32","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/how-do-i-filter-the-current-items-list-of-a-listbox-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:32","modified_gmt":"2022-08-30T15:23:32","slug":"how-do-i-filter-the-current-items-list-of-a-listbox-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-do-i-filter-the-current-items-list-of-a-listbox-collection-of-common-programming-errors\/","title":{"rendered":"how do i filter the current items list of a listbox?-Collection of common programming errors"},"content":{"rendered":"<p>I have a listbox that is populated with a list of List items. The collection is completely unfiltered. What I am trying to accomplish is creating the ability to filter the listbox and reorder the listbox based on two different criteria. The first being filter by status. I have a combobox that contains all of the different statuses. I have accomplished this like so:<\/p>\n<pre><code>public void ConstrainList()\n        {\n            if (((Lut_status)cboStatus.SelectedItem).ID != 8)\n            {\n                lbxHoldList.ItemsSource = allHolds.Where(a =&gt; a.FullHoldRecord.HoldStatus == ((Lut_status)cboStatus.SelectedItem).ID);\n            }\n            else\n            {\n                lbxHoldList.ItemsSource = allHolds.Where(a =&gt; a.FullHoldRecord.HoldStatus != 7);\n            }\n        }\n<\/code><\/pre>\n<p>This is a method that runs when the combobox selectionchanged event fires. This works fine. Where I am getting muddled up is I need to resort the constrained list based on one of 3 criteria using radio buttons. So I was thinking I could just grab the ItemsSource object, sort it with linq and then reassign it doing something like:<\/p>\n<pre><code>lbxHoldList.ItemsSource = ((List)lbxHoldList.ItemsSource).OrderBy(a =&gt; a.FullHoldRecord.DateOpened);\n<\/code><\/pre>\n<p>This works the first timem, but starts crashing with each subsequent call. I don&#8217;t feel like this is the best way to go about this. Can someone help me either fix this approach or show me a better way to do this? Thanks<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-05 09:49:00. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a listbox that is populated with a list of List items. The collection is completely unfiltered. What I am trying to accomplish is creating the ability to filter the listbox and reorder the listbox based on two different criteria. The first being filter by status. I have a combobox that contains all of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2278","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2278"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2278\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}