473,320 Members | 2,161 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,320 software developers and data experts.

Searching Display Data with BinarySearches

I have implemented custom sorting and searches on my complex objects (they
contain properties and collections) using IComparer and BinarySearch. I knew
they before doing a search you had to sort your collection, but I found out
the hard way yesterday that it has to be sorted on the same property as you
are searching on. Fine. But now my problem is that while displaying this
collection data to the user I have to search on a different property then the
collection is currently sorted on.

For example, the user has chosen to sort the data on PropertyA. An event
happens and I need to find an item in the collection based on PropertyB. It
does not work unless I sort the collection on PropertyB first. If I do this,
then the data the user sees changes. Very bad.

So I guess what I am asking for is a way to search a collection, return the
requested object (index) without disturbing the original data (collection).
Any ideas?

Thanks!
David McCarter

=====================
David McCarter
www.vsdntips.com
Nov 17 '05 #1
2 1103
David,

Well, you don't have to use a binary search in this case. You could
cycle through all of the items in the collection, and just do a straight
comparison against them.

Or, you could create a new collection (where there is nothing bound to
it, like the ui), add the elements to that collection in the proper sorted
order, then perform your binary search.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"dotNetDave" <do********@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
I have implemented custom sorting and searches on my complex objects (they
contain properties and collections) using IComparer and BinarySearch. I
knew
they before doing a search you had to sort your collection, but I found
out
the hard way yesterday that it has to be sorted on the same property as
you
are searching on. Fine. But now my problem is that while displaying this
collection data to the user I have to search on a different property then
the
collection is currently sorted on.

For example, the user has chosen to sort the data on PropertyA. An event
happens and I need to find an item in the collection based on PropertyB.
It
does not work unless I sort the collection on PropertyB first. If I do
this,
then the data the user sees changes. Very bad.

So I guess what I am asking for is a way to search a collection, return
the
requested object (index) without disturbing the original data
(collection).
Any ideas?

Thanks!
David McCarter

=====================
David McCarter
www.vsdntips.com

Nov 17 '05 #2
Dave.... In the ancient past having written file based data storage, I
look at the problem as data and index. You can have more than one index
for the data. The index simply contains pointers to the actual data
bucket and you can sort and search a given index. So off the top of my
pointed head I would consider creating a separate sorted index. Perhaps
an arraylist that is synchronized with the data. Now this could get
messy but there are ways to obtain a sync lock on a collection, do a
foreach on the locked collection, generating an array list, and then
releasing the lock, sorting and searching the arraylist.

Regards,
Jeff
So I guess what I am asking for is a way to search a collection, return
the requested object (index) without disturbing the original data
(collection).
Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3

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

Similar topics

10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
8
by: David | last post by:
Hi, I have a form as follows: Main Form (To Select Customer) Sub Form 1 (To Select PO Number, by clicking on field) - Continuous form Sub Form 2 (To view order details)- Continuous form...
0
by: fig000 | last post by:
Hi, I'm trying to use the sqldatasource control and a detailsview to create a fully functional data entry screen; it's quite easy. I can see the strength of creating a master grid associated...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
1
by: Aprile | last post by:
Hello, everyone. I would like to ask something about searching Chinese simplified characters from the database. Every time I searched, it won't display data, but if I searched without a condition it...
0
by: cannonpm | last post by:
Greetings and salutations. I have developed an A2K3 MDB and have a search form modeled after Allen Browne's search form (http:// allenbrowne.com/ser-62.html). It works well except for records which...
2
by: wietmie | last post by:
Hai, i just wanna ask, is it possible to do a searching result like google using VB6.0, but google are too complicated, what i mean just, user put the searching word in the textbox, then it will...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
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...
1
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.