473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Collection Item(index as string)

I have the following function in my WidgetCollection class.
What is a more efficient way of doing this?
I tried the commented code below, but I couldn't get it to work.

Public Overloads ReadOnly Property Item(ByVal index As String) As
Widget
Get
Dim CurrentSetting, ReturnBO As Widget

For Each CurrentSetting In Me.InnerList
If CurrentSetting.DisplayID = index Then
ReturnBO = CurrentSetting
End If
Next

Return ReturnBO
End Get
End Property

I know this is a dumb question, but does all this go in the class,
collection class or factory?
'Private Shared mProperties As
System.ComponentModel.PropertyDescriptorCollection
'Protected Friend Sub New(ByVal creator As BizObjectFactory)
' MyBase.New(creator)
' mProperties = System.ComponentModel.TypeDescriptor.GetProperties (GetType(Widget))
'End Sub
'Default Public Overloads Property Item(ByVal name As String) As
Widget
' Get
' Return mProperties(name).GetValue(Me)
' End Get
' Set(ByVal value As Widget)
' mProperties(name).SetValue(Me, value)
' End Set
'End Property
Nov 21 '05 #1
2 1672
Bill,
If you are wanting to store items in a collection using a key (ie the
DisplayID property of the Widget), use a collection which derives from
DictionaryBase.
This is an very fast way of retrieving items with a unique key

Public Class WidgetCollection
Inherits DictionaryBase

Default Public ReadOnly Property Item(ByVal ID As String) As Widget
'Gets the widget with the specified ID
Get
Return DirectCast(MyBase.InnerHashtable(DisplayID), Widget)
End Get
End Property

Public Sub Add(ByVal widget As Widget)
'Add the widget to the collection using its ID as the key
Try
'Use Dictionary methods to raise events
MyBase.Dictionary.Add(widget.DisplayID, organisation)
Catch ex As ArgumentException
'The widget already exists so replace it
MyBase.Dictionary.Item(widget.DisplayID) = widget
End Try
End Sub

Note: The following code might have been better (avoids having to continue
the loop once the item has been found)
Dim eWidget as Widget
For each eWidget in MyBase.InnerList
If eWidget.DisplayID = index
Return eWidget
End If
Next

Stephen
"Bill Ray" <ri***@mail.com> wrote in message
news:63*************************@posting.google.co m...
I have the following function in my WidgetCollection class.
What is a more efficient way of doing this?
I tried the commented code below, but I couldn't get it to work.

Public Overloads ReadOnly Property Item(ByVal index As String) As
Widget
Get
Dim CurrentSetting, ReturnBO As Widget

For Each CurrentSetting In Me.InnerList
If CurrentSetting.DisplayID = index Then
ReturnBO = CurrentSetting
End If
Next

Return ReturnBO
End Get
End Property

I know this is a dumb question, but does all this go in the class,
collection class or factory?
'Private Shared mProperties As
System.ComponentModel.PropertyDescriptorCollection
'Protected Friend Sub New(ByVal creator As BizObjectFactory)
' MyBase.New(creator)
' mProperties =
System.ComponentModel.TypeDescriptor.GetProperties (GetType(Widget))
'End Sub
'Default Public Overloads Property Item(ByVal name As String) As
Widget
' Get
' Return mProperties(name).GetValue(Me)
' End Get
' Set(ByVal value As Widget)
' mProperties(name).SetValue(Me, value)
' End Set
'End Property

Nov 21 '05 #2
We have many applications which inherit from our CoreCollectionClass
which inherits from CollectionBase. So changing to inherit from
dictionary class sounds risky.
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: honeybee | last post by:
How to get the item value from a specific Item Index in the listbox?
0
by: Webermax | last post by:
Hello, I want to retrieve the index of the selected item in a context menu synchronously. I coded something like this : MyContextMenu mcm; mcm = new MyContextMenu (); mcm.MenuItems.Add (new...
2
by: George Addison | last post by:
How do I test for the value of the repeater's item index: SOmething like: Select Case Container.ItemIndex if container.itemindex
3
by: Stimp | last post by:
I have a datalist that outputs a link to a picture in each ItemTemplate: e.g. <asp:DataList id="DataList1" ...etc> <ItemTemplate> <a href='Pic.aspx?pic=somenumber'>picture</a> </ItemTemplate>...
2
by: Adam Knight | last post by:
Hi all, I am wanting to display a data lists item index inline in a script. Meaning not from code behind but <%# %> ect. Obviously i can display a dataitem by using: <%#...
0
by: Leonardo Santos-Macias | last post by:
I have a dropdown list that I bind at runtime. It does postback to the server. If I select any item, it will trigger the SelectedIndexChange event. My problem is that it doesn't trigger the...
11
by: Bill nguyen | last post by:
Table A has 2 columns: recID int recName String I need to load all recName into combobox B using B.Items.Add(recName). This is no problem. However, I would like to be able to match ComboxBox...
2
by: B | last post by:
I'm trying to simply build a form with a combo box containing a list of states. I'd like for there to be NO default selected item, but invariably, the first item in the DataSource is being...
0
by: Bruno Neves Pires Silva | last post by:
Hello, everybody. How can I get the selected item index in a DataGridViewComboBoxCell, in a datagridview?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.