.NET And LinQ: How To Delete Entries From A Dictionary Using The Value

Jun 7, 2010

I have a dictionary collection as bleow:

mydic.addvalue(key1, val1)
mydic.addvalue(key2, val1)
mydic.addvalue(key3, val1)
mydic.addvalue(key4, val2)
mydic.addvalue(key5, val2)

From the above dictionary I want to delete all the entries where value == "val1", so that the result would have only following entry:

mydic.addvalue(key4, val2)
mydic.addvalue(key5, val2)

My VB source code is on VS2008 and targeted for 3.5

View 1 Replies


ADVERTISEMENT

Use LINQ To Omit Some Entries In The Value Part Of A Dictionary And Project This Into A New Dictonary Maintaing Original Keys

Nov 18, 2009

I have a generic dictonary which is templated in the following manner:

[code...]

If I wanted to omit certain list items against arbitrary keys (that is the items that are in the list contained within the value part of each of the key value pairs making up the dictionary) given some arbitrary condition (lets say omitting list items where a list item contained the string "abc")

I would expect to able to create/project into a new dictionary which would contain entries which contained lists WITHOUT those items whose name contained "abc"

How do I achieve this using a Lambda expression?

I was trying something like this:

[code..]

View 2 Replies

Use Linq ToDictionary To Return A Dictionary With Multiple Values In The Dictionary Items?

Jan 25, 2010

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.

[Code]...

View 2 Replies

Flatten A Dictionary Of Dictionaries And Sum The Values Of The Inner Dictionary With LINQ?

Apr 16, 2012

I have the following object:

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)

The best result I could get was:

Lookup(of MasterCategory, Dictionary(of Date, Integer))

From:

countDictionary.ToLookup(Function(o) o.Key.MasterCategory, Function(o) o.Value)

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

[code]....

View 1 Replies

.net - Filter Custom Dictionary With LINQ ToDictionary - "Unable To Cast Object Of Type 'System.Collections.Generic.Dictionary`2"

Jul 7, 2010

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.

Here's the simplified version of my code:

[Code]...

View 2 Replies

Delete MicrosoftCom3Selfreg Entries?

Aug 20, 2009

I'm using the MS example script [URL] to install a COM+ application. For uninstall I have a script that shuts down the app, calls Remove from the Catelog App Collection, and then I call regsvr32 /u. This cleans up the COM entries and removes my app from the catelog but leaves behind the CoClass and Interfaces in HKEY_LOCALSoftwareMicrosoftCom3Selfreg. How should the script remove the SelfReg values?

objCatalog.ShutdownApplication(myAppName)
objApplicationsColl.Remove(iCounter)
objApplicationsColl.SaveChanges()

[code]....

View 2 Replies

Delete Multiple Entries From Listbox

May 7, 2010

I am trying to delete multiple selected entries from a listbox. When I run the code I have now, instead of deleting all of the items that are highlighted, it deleted all the items in the listbox.[code]

View 1 Replies

Sort Blank Entries To Bottom Of LINQ Query?

Dec 2, 2009

I am trying to sort a LINQ to SQL query based on two fields. The first field is occasionally null which automatically sorts to the top of an ascending query. Is there any way to make the null entries sort to the bottom?

Here is an example:

From x in SampleDataContext.Event _
Order By x.Date, x.Sequence_Number _
Select x.Date, x.Sequence_Number

[code]....

View 1 Replies

Doesn't The Union Function In LINQ Remove Duplicate Entries?

Aug 9, 2009

I'm using VB .NET and I know that Union normally works ByRef but in VB, Strings are generally processed as if they were primitive datatypes.Consequently, here's the problem:

Sub Main()
Dim firstFile, secondFile As String(), resultingFile As New StringBuilder
firstFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "1.txt").Split(vbNewLine)
secondFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "2.txt").Split(vbNewLine)

[Code]...

View 2 Replies

.net - Sorting A Dictionary By Value With Linq?

Mar 23, 2012

I'm trying to sort a dictionary by value with LINQ but I can't figure how the ToDictionary() method works.

All the examples I can find are in c#.

here's my code

Dim f As Dictionary(Of String, String) = (From value In projectDescriptions.Values
Order By value Ascending
Select value).ToDictionary(???)

[Code].....

View 3 Replies

How To Query Dictionary(OF T , T) By LINQ

Mar 31, 2010

In My Code i am using Dictionary(Of String , String) As Key Value Pair ..While i am using LINQ to Query this Dictionary, It Shows Dictionary is not Queryable.

View 1 Replies

LINQ And Generic Dictionary?

Jan 2, 2010

As I am beginner in LINQ, I have small problems. I have dictionary of Char and Long, and I would like to use LINQ to retrieve Char with highest Long Value. I saw some C# samples, which look pretty easy, but I can't achieve such expression in VB.Here are two expressions, and I don't think they are most efficient possible.

[Code]...

View 14 Replies

LINQ Query On A Dictionary?

May 23, 2012

This should be extremely simple but I'm still new to the language and don't grasp the basics yet.

[Code]...

View 1 Replies

VB And LINQ Query On A Dictionary

May 23, 2012

I need a simple LINQ query on VB.NET on the dictionary [Code] What I need here is to retrieve a SINGLE website (dictionary value of string type) or NOTHING (if the query cannot find an affordable result) given those rules: The dictionary key (integer) must be greater than startSite and not equal to mainSite or returnSite (both must be excluded from the result) Any hint? [Code]

View 2 Replies

VS 2008 Delete All Words From Dictionary?

Apr 20, 2010

I'm trying to delete all words from my dictionary. I get this error. How can I fix this?

vb.net
For Each word In dictionary
dictionary.Remove(word.Key)
Next

This is my error Collection was modified; enumeration operation may not execute.

View 13 Replies

Linq - .NET Order Dictionary Alphabetically?

Mar 14, 2012

I have a Dictinary(Of String, Item) and I'm trying to sort it into alphabetical order by the item name. I don't want to use a sorted dictinary and without it, I've having zero luck. Linq is not my strong point.

[Code]...

View 2 Replies

Avoid For Loop (Dictionary Array) Using LINQ?

Nov 23, 2010

How to avoid for loop (Dictionary Array) using LINQ

View 1 Replies

Get The Corresponding Key For The Maximum Value In A Dictionary(Of SomeEnum, Integer) Using LINQ?

Dec 11, 2009

I've got a Dictionary(Of SomeEnum, Integer) that gets filled up while looping through some objects that have a property with type SomeEnum. Once the loop is done, I want the SomeEnum type that occurs the most in the list of objects. I also need the other counts as well for display purposes, hence the usage of a simple Dictionary(Of K, V).I am looking for a LINQ query to give me back the SomeEnum key that occurs the most by looking at each keys number of occurences. Or perhaps there's an easier way of going about it.I could do this:

Return (From kvp As KeyValuePair(Of SomeEnum, Integer) _
In Me.MyObjects Order By kvp.Value Descending _
Select kvp).First().Key

But wouldn't the sorting be a more expensive operation than trying to wiggle Max() in there somehow?

View 1 Replies

Returning Subset Of Dictionary With A Complex Type As A Key With Linq

Oct 5, 2010

I have a collection as follows

Private _bankRates As Dictionary(Of RateSourceBank.Key, RateSourceBank)

Where RateSourceBank.Key is simply

Public Class Key
Public RateType As String
Public EffectiveDate As DateTime

[Code].....

View 1 Replies

Linq Query On Dictionary<TKey, TValue> Working As DataSource?

Dec 21, 2010

I have the following in VB:

Dim sources = From source In importSources Select New With _
{.Type = source.Key, .Source = source.Value.Name}
dgridSourceFiles.DataSource = sources

[code]....

View 2 Replies

Linq To Objects - (C#) Creating A Dictionary From An Existing List Without Looping?

Aug 31, 2011

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?

View 3 Replies

String Search Listbox Entries To Avoid Duplicate Entries In VB 2008?

Nov 29, 2009

I have a program where you have three entries, CD name, artist, price and it goes into a listbox and .txt file when closing. I have to have a message box if you enter the same CD name. I have a code to open the .txt file and compare strings but I need to change it to compare only the CD name and not all three entries. Is there a way to do my string compare against my listbox without opening the .txt file?? The program loads the listbox from the .txt file when opening. Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click' adds CD information to the list box

' declare variables
Dim strName As String
Dim strArtist As String
Dim strPrice As String

[code].....

View 4 Replies

Modify Table Entries Based On Other Entries?

Jun 22, 2010

I want to set a certain column to true or false automatically based on what value another column has entered. I managed to get this working by myself using the 'SQL Pane' in VB and testing it by using execute sql but I don't know what to do now. I assumed that I could just save it and it would work from there but that's not the case, it dissapears from the SQL Pane if I close the project (even though it worked fine when I ran the project the first time), so where do I put it/what do I do with it in order to get this to work?

View 1 Replies

Use LINQ To Filter Collection Of Nested Classes To Yield Dictionary Of Unique Properties Of Those Classes?

Jan 23, 2012

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.

View 2 Replies

Asp.net - LINQ - Putting Result In A Dictionary(Of String, Integer), Where The Integer Must Be 0?

Sep 19, 2011

I have a LINQ2Entity problem, I want to get the value, string, from a database, so I select FProducts.Serial_number, and to end the query, I do .ToDictionary. The problem is, it tells me that it doesn't have sufficient parameters, to convert ToDictionary. So I need something like select FProducts.Serial_number, Nothing). ToDictionary. Also FProducts.Serial_number, 0).ToDictionary doesn't work.

Sub GetStatistics(ByVal ProductNumbers As List(Of String), ByRef Passed As Integer, ByRef FailedProducts As List(Of String))
Passed = 0
FailedProducts = Nothing

[Code]...

View 2 Replies

Button Delete Row In Datagridview Use LINQ?

Nov 18, 2011

I want to know how to delete record (row) in transaction.this is details :

label for show productID
textbox for insert product name
datagridview for show data
insert button
delete button
edit button

[Code]...

View 8 Replies

Dictionary In A Dictionary - Collection Of Data To Pass Back ?

Apr 27, 2009

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

[CODE].........................

View 2 Replies

Compare Two Datatable And Delete Some Rows By Linq?

Nov 18, 2010

there is two datatable at some datasetsone of them is tbl1 and fileds is (pcode,points) other table is tbl2 and fields is (pcode,stoped)"pcode" is equal at two tables

View 6 Replies

LINQ To SQL Generic Class For Insert And Delete Operation?

Nov 27, 2009

I have been writing same code for insert, update, delete with LINQ over and over again. I want to have some sort of generic function for Insert, Update, Delete operation. I read a post here like the following :

public static void Insert<T>(T entity) where T : class
{
using (OrcasDB database = new OrcasDB())

[code].....

View 2 Replies

Update,Delete And Add To A Datagridview With Underlying Tables Using LINQ?

Jan 19, 2010

I'm looking for a simple example in VB2008 code.I have the Northwind DB installed on one of our SQL servers.

I've worked with the Datagridview on serveral occasions but never used its update,delete or add functions. I've Googled around the web, but could not find a simple example.

Whats the best way to do this and implement it using LINQ?

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved