I know I can do this with a for loop cause that's how i'm doing it now. I was hoping for a more efficient way to accomplish the task.
I have a dictionary(Of Integer, Boolean) or Of String, Boolean. i want to get a list(of integer) or Of String from the dictionary where all the values are true(or false depending on what i need at the time)
and to generalize it or "black box" it, it could be any dictionary(of whatever, whatever) and return a list(of whatever) where the value = whatever i'm looking for at the time.
string, string where value = "Closed"
in short: i want all list of all the keys who's value = some criteria
my current code:
Public Function FindInDict(Of tx, ty)(thedict As Dictionary(Of tx, ty), criteria As ty) As List(Of tx)
Dim tmpList As New List(Of tx)
I want to group items from a linq query under a header, so that for each header I have a list of objects that match the header title. I assumed the solution would be to use ToDictionary to convert the objects, but this allows only one object per "group" (or dictionary key). I assumed I could create the dictionary of type (String, List Of()), but I can't figure out how to write it. As an example I have written a simplified version below.
I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.
Following code properly populates "wksSheetNames" Dictionary
Dim wksSheetNames As New Dictionary(Of String, String)
For Each Wks In xlsWB.Worksheets
Wks.Activate() wksSheetNames.Add(xlsApp.ActiveSheet.codename, xlsApp.ActiveSheet.name) Next
For example assume the code logic is correct (I know that the syntax is not correct)If wksSheetNames.(Key="Sheet2", Value="Inventory") then Stop What is the correct VB.Net syntax to "Stop" in the above line?
I am trying to return a vb2010 dictionary to vbscript. I posted this to the vbscript forum with no luck, so I thought I would try here.The code for vb2010 is below, and works fine within VB2010:
Public Function TestDictionary() As Dictionary(Of String, String) Dim dic As New Dictionary(Of String, String) dic.Add("1", "Tval1")
I have an ASP.NET MVC 2 application in which I am creating a custom action filter. This filter sits on the controllers in the application and verifies from the database whether that function is currently available.[code]....
I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.
I have a Dictionary with key of type UInteger and the value is List(Of Session) where the (Public) class Session contains a couple of variables and a constructor (Public Sub New(...)). Some of the variables in my Session class is:
Private count As Integer Private StartDate As Date Private Values As List(Of Integer)
and a couple of methods like:
Friend Sub Counter(ByVal c as Integer) count += c End Sub
There is no problem to add values to the Dictionary:
Dim Sessions As New List(Of Session) Dim dict As New Dictionary(Of Integer, List(Of Sessions))
then some code to fill up a couple of Session objects in Sessions (not shown here) and then:
i want to know how to manipulate the data from a Public ListD As New List(Of Dictionary(Of String, String))meaning read/write I've tried with ListD.Add("string_as_key", var_as_value) but it haven't worked?
That was probably bad title, but I'll illustrate what I'm trying to do. I have a method in a class that I need to call several times. The method returns a List(Of String). I'm just grabbing some information from a database.
VB.NET Public Function GetTestList() As List(Of String) Dim int As Integer = 0
I don't know if this is doable, maybe with Linq, but I have a List(Of MyType):
Public Class MyType Property key As Char Property description As String End Class
And I want to create a Dictionary(Of Char, MyType) using the key field as the dictionary keys and the values in the List as the dictionary values, with something like:
New Dictionary(Of Char, MyType)(??)
Even if this is doable, internally it will loop through all the List items, I guess?
I have a listview populated from a database (im a bit of a novice with programming) and i want to be able to type a surname into a textbox and search the listview for that person. I can easily populate textboxes from searching the database but am unsure how to "filter" the listview so if i type "jones" into the surname box it only displays the people in the listview who have the surname jones.
I would like my gridview to be filtered by the dropdown list I have. It is pulling specific information from the database, so when you choose a value from the dropdown list, it should search through all the records and find only records with the ddl value in them.
The code that I am using in the codebehind for the SelectedIndexChanged is not right though. I get an error message saying 'Value' is not a member of 'Integer'. This is on the line dsCompanyFilter.SelectParameters.Add
It probably has something to do with the gridview not tying to the dropdown list properly, but I am not sure how to fix that code.
I'm trying the fetch only the date within the current and return how many rows Dim dc as new dataclassesdatacontext dim q=from p in dc.worktime where p.name.equals(session("name") and p.date ).count what I should I put after "p.date" ? And if I want to search for the record which there are record that are insert five days earlier, how to do that ? use (datetime.now - 5) ?
After reading all the examples for list of T exists and Find and find first, none show how to handle multi-property objects. Below is bare bones example maybe someone could flesh out to show how this should be done.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DatePriceList As New List(Of DateAndPrice) DatePriceList.Add(New DateAndPrice(Date.Parse("1/1/2000"), 10.12)) DatePriceList.Add(New DateAndPrice(Date.Parse("1/2/2000"), 11.12))
I have created a class with a function in it. I have a collection of data I want to pass back. I tried an arraylist first. Now I am trying to use a dictionary. My problem is that it creates the dictionary ok, but I am only get the last row of data from my
Function GetWeldAuditInfo(ByVal ResourceId As String, ByVal VendorId
countDictionary As Dictionary(of Category, Dictionary(of Date, Integer))
The Class has a Enumeration Property. For the purposes of demonstration, I'll call it MasterCategory.I have been trying to get out an object that looks like the following:
groupedCountDictionary As Dictionary(of MasterCategory, Dictionary(of Date, Integer)
Which results in a IEnumerable (Of Dictionary(of Date, Integer)) for each MasterCategory value.However, I need that IEnumerable of Dictionary flattened to one dictionary with all the integers summed (total counts) for each date. I then tried to use various selects and group bys (from numerous stackoverflow posts) to "flatten" it, but my efforts have fallen short.
Current Code
[Category Class] - MasterCategory As Enum - Name As String etc
I have a list of 100,000 urls in list(Of string) which can contain urls in the form.[URL]..i have tried using a combination of regex and the Uri class, but that didn't help, so i dumped the code. i also tried using this code, but it will only remove duplicatse of exact form, since its not domain specific.
list = new ArrayList<T>(new HashSet<T>(list))
How filter these duplicates and keep just one of these url if it contains the same name e.g yahoo.
all URL are of different domains, but can usually have duplicates like the example i gave above
how can I get the list of Items proposed by the AutoFilter function for a column in an excell sheet (Excell 2003)? For example: I have activated the AutoFilter in an Excell sheet.In the column A, the filter propose (All), (Top 10), (Custom...), A, B, C, (Blanks), (Non Blanks).I want to retrieve in Visual Basic the items A, B, C.
I would like to write a generic function that would search a List(Of T) for all elements of type TFilter and return a List(Of TFilter) which comprises those elements.
I've tried this: Public Function FilterList(Of T, TFilter)(ByVal ListToFilter As List(Of T)) As List(Of TFilter) Return ListToFilter.FindAll(Function(z) z.GetType.Equals(GetType(TFilter))).ConvertAll(New Converter(Of T, TFilter)(Function(z) CType(z, TFilter))) End Function
But, it gives the following error: Value of type 'T' cannot be converted to 'TFilter'.
I am trying to write a query for an existing database, I am using LINQ on EF3.5 inside VS2008 as that is the only environment available to me.I have a starter query that gives me a list of items so the user can select what they want.
"e.Result = From c In MLDb.TBL_FeatureInfoSet Order By c.INSP_ROUTINE_NM Select c.INSP_ROUTINE_NM Distinct"
The user can then select from the list one or several items they are intersted in and i want to use these as the filter in a further database call. It's not then difficult to have a where to filter on one string however, I would also like to be able to allow the user to select several items from the list box and the data for all of those to be returned.
I would like to know how to filter out system tables and only return user tables .when i run the code it displays lists of system tables with user tables list in combobox.I have just gotten into vb.net and have tried few ways to do this but dont understand well enough.
This post is similar to one I have posted before about a dropdown filtering results in a gridview. Well now I need this dropdown to attach itself to a repeater that will filter results into a gridview. I have tried rptLetters.DataBind() in the code behind of the dropdown list, but that doesn't seem to be changing any of the letters at the top of the page when I click on different items in the dropdown list.The screenshot doesn't show enough of the products, but in this case it skips from G to L, and in the repeater the letters between G and L are still shown. I need to be able to get that repeater to recognize the letters that start each of the products associated with the company chosen.
Could not find this through Google or in SO questions.I have a checkbox listbox on my form. I want to filter my List by the list of selected Ids from that listbox that are checked, in SQL I would have done this like "Where TypeId In (1, 4, 5, 7)"... how do I do that in LINQ?
I feel like I am missing a really obvious answer, but cannot get it.
For argument sake... here is the what I have for sample data: