moongodess Posted September 30, 2005 Posted September 30, 2005 I have two classes: Friend Class clsItem Public Sub New(ByVal objId As Object, Optional ByVal objNr As Object = Nothing, _ Optional ByVal objCode As Object = Nothing, Optional ByVal objDesc As Object = Nothing) Try Id = objId Nr = objNr Code = objCode Desc = objDesc Catch ex As Exception InfoError(ex) End Try End Sub Private mobjId As Object Public Property Id() As Object Get Return mobjId End Get Set(ByVal Value As Object) mobjId = Value End Set End Property Private mobjNr As Object Public Property Nr() As Object Get Return mobjNr End Get Set(ByVal Value As Object) mobjNr = Value End Set End Property Private mobjCode As Object Public Property Code() As Object Get Return mobjCode End Get Set(ByVal Value As Object) mobjCode = Value End Set End Property Private mobjDesc As Object Public Property Desc() As Object Get Return mobjDesc End Get Set(ByVal Value As Object) mobjDesc = Value End Set End Property End Class Friend Class clsItemCol Inherits CollectionBase Public ReadOnly Property Item(ByVal index As Integer) As clsItem Get Return CType(MyBase.List(index), clsItem) End Get End Property Public Sub Add(ByVal item As clsItem) MyBase.List.Add(item) End Sub Public Sub Remove(ByVal item As clsItem) MyBase.List.Remove(item) End Sub End Class This is supposed to be used as collections, to fill some combos with specific values. Recently I verified that filling the collection is taking too long, and I dont know why. I'm doing something like: Dim colData As clsItemCol colData = New clsItemCol colData.Add(New clsItem(1, 3, "Item3", "Description3") (...) Does anyone have an idea, or some other way of doing this?? Thankx Quote
Administrators PlausiblyDamp Posted September 30, 2005 Administrators Posted September 30, 2005 How long is too long exactly? One thing you might want to do to speed things up is look at using a HashTable rather than a collection. Also is there a reason why you have declared just about every single data type as object rather than the actual data type of the values you want to store? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
moongodess Posted September 30, 2005 Author Posted September 30, 2005 Sometimes it is taking more than 2 seconds to fill a collection with 10 items, for example. I declared everything as object because this is a 'generic colecction' wich i'll use many times, to different variable types. Do U think this can be a cause? How do I use an HashTable? I'm new at Vb.Net and I never heard about it :rolleyes: Quote
*Experts* Nerseus Posted September 30, 2005 *Experts* Posted September 30, 2005 If your goal is to fill a ComboBox, I would generally use an ArrayList to hold my collection of custom objects. Still, 2 seconds is far too long. Is this confirmed with some kind of timing code? Also make sure you use Release Mode as your guide, Debug mode may take extra long sometimes. Also it would be nice if even your custom object could make some kind of assumption like an item has only an ID and Text property with maybe an optional "object" property to store more data. I've filled combos with literally thousands of custom classes (I wouldn't do it again - thousands is too many) and it always took less than 2 seconds. My class was a custom object with an Integer ID and a string Text property. I generally loop through a DataSet and create objects on the fly, filling an ArrayList that will get bound. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.