I create a dictionary
Dim ImageCollection As New Dictionary(Of ConvensionImages, Integer)
and I fill that
For Each dr As DataRow In dt.Rows Dim obj As New ConvensionImages obj.ImageID = dr("ID") obj.Name = dr("Name") obj.Description = dr("Description") obj.CategoryID = dr("CategoryID") obj.CategoryName = dr("CategoryName") obj.CategoryDescription = dr("CatDescription") obj.EventID = dr("EventID") obj.Image = dr("img") obj.DownloadImage = dr("DownLoadImg") ImageCollection.Add(obj, key) key = key + 1
now I want to search ImageID and key how can I do this
To iterate through the dictionary's keys, utilise the keys() method that is supplied by the dictionary. An iterable of the keys available in the dictionary is returned. Then, as seen below, you can cycle through the keys using a for loop.
How to VB.Net Dictionary. A Dictionary class is a data structure that represents a collection of keys and values pair of data. Each item is a combination of a key and a value. ( key-value pair)
Make Integer
as key for your Dictionary:
Dim ImageCollection As New Dictionary(Of Integer, ConvensionImages)
Change ImageCollection.Add(obj, key)
to ImageCollection.Add(key, obj)
And use this loop:
For Each kvp As KeyValuePair(Of Integer, ConvensionImages) In ImageCollection Dim v1 As Integer = kvp.Key Dim v2 As ConvensionImages = kvp.Value 'Do whatever you want with v2: 'If v2.ImageID = .... Then Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With