Linq Condition help - vb.net
-
Wednesday, February 13, 2013 9:57 PM
I have a list box where users can select multiple items. Options available in the list box are added below.
1st option is select all and is selected by Default. if selectall is selected I need to make the linq query not to validate for any condition. (should display all) if not I need to filter for the values selected how can I do that?? options ================ selectall Level1 Products Level2products Level3Products Dim Query = (from p in Dc.Products Join O on Dc.Orders On p.ProductId equals O.ProductId where o.Status = "Delivered"
/***Here I need Add the listbox filter condition smething like ddlitem.selectedValues.contains(p.level)***/ Select ProductId = p.ProductId.Tostring(), _ OrderStatus = O.OrderStatus.tostring(),_ OrderNumber = O.OrderNumber(),_ ProductLevel = p.Level())
How can I do that?? I am a newbie in linq.
Thank you,
Lily
All Replies
-
Thursday, February 14, 2013 9:57 AMModerator
Hi Lily,
If you are using WinForms ListBox control, there is SelectedItems property to indicate the selected items. If p.level has the some text with items in ListBox, you can add the filter condition in where statement, like:
Dim Query = From ... In ...
Where o.Status = "Delivered" AndAlso ListBox1.SelectedItems.Contains(p.Level)
Select ...
If the text in p.Level is not the same with the text in ListBox's items, you would probably use Where() method and pass a Func<> delegate. Return True when the item is needed after filtering. ListBox's SelectedIndices property can be used to determine which item is selected.
Best regards,
Chester Hong
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by ALily Friday, February 15, 2013 8:15 PM
-
Friday, February 15, 2013 8:15 PM
got it resolved. I am adding all the items to a list (ListAll) and doing Listselected where I am adding Only selected items from the dropdown if ddlitem.selectedIndex = 0, listall.contains(p.level), listselected.contains(p.level)
- Marked As Answer by ALily Friday, February 15, 2013 8:15 PM

