Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Wanna-Be C# Superstar
Posted

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 connection

Northwind.zip

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.

Posted

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???

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...