haroldjclements Posted July 20, 2004 Posted July 20, 2004 Hello All, I am just wandering if anyone has a better way of implementing the following: I am drawing search results (description of an item) from a database and populating them in a listbox. I need to map the element numbers, that are automatically allocated to the items when added to the lsitbox, to the description’s unique ID. I can’t use an array because I don’t know the length of the search results. The only way to do this is to do a ‘count’ in the SQL statement then go back and populate the listbox and array. However this idea will be time consuming. Another idea I have was to use a Vector (as they grow and shrink to your needs). The problem with this is that a Vector collection does not collect raw data types, which means each search result will be an object, which will use lots of memory. The last way I thought of was to limit the search results to 50, that way I will be able to create an array of size 50 and just display a message requesting the user to narrow down the search criteria. I was wandering if anyone had any better ideas for mapping the elements? Thanks for your time, Harold Clements Quote
VBAHole22 Posted July 20, 2004 Posted July 20, 2004 Could an ArrayList work for you? Another thing that can be done is that you can use an array and then when you loop through your datareader (or whatever you use) you redim the array each time to allocate for the growth. You could use mod and only redim say every 10 times. I think you would need to preserve as well. Or you could just allocate a huge array but that doesn't sound so great either. I think you are on the right track with limiting the resultset. You don't want to tug a huge amount of data from the db anyway. You could always let the user page to the next set of 50. Quote Wanna-Be C# Superstar
haroldjclements Posted July 27, 2004 Author Posted July 27, 2004 Thanks for your input VBAHole22, its very much appreciated. Quote
pelikan Posted July 27, 2004 Posted July 27, 2004 download C# Express and use generics ! Quote IN PARVUM MULTUM
Joe Mamma Posted July 28, 2004 Posted July 28, 2004 Another idea I have was to use a Vector (as they grow and shrink to your needs). The problem with this is that a Vector collection does not collect raw data types, which means each search result will be an object, which will use lots of memory. whoa. . . bad design precept!!!!! everything is an object in .net. why are you worried about creating objects. . . memory is way cheap. . . debugging isnt!!! See attached code. Check the shared event handlers of the list box (double click on a list item.) Check the abstract classes. app requires local trusted Northwind SQL connectionNorthwind.zip Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 29, 2004 Posted July 29, 2004 code change. . . change the line: NorthwindClass nw = lb.SelectedItem as NorthwindClass; to: INorthwindClass nw = lb.SelectedItem as INorthwindClass; in listBox1_DoubleClick thats what I meant to do. . . why declare the interface if I am not going to use it??? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
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.