473,809 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1127
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.co m

"dotNetDave " <do********@dis cussions.micros oft.com> wrote in message
news:66******** *************** ***********@mic rosoft.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
5495
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 problem that I am facing is in dealing with (privacy) critical information like credit-card #s and SSNs or business critical information like sales opportunity size or revenue in the database. The requirement is that this data be stored encrypted...
8
1604
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
1225
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 with a detailsview that gives you access to the record you choose in the grid. However one of the basic functions of this type of screen is the ability to enter a search term and have the grid display the record that is closest the search term....
7
2624
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 string will often not produce a direct match, the results will be based on proximity (50%, 20% 100%, etc). are there any good examples out there on how to do keyword searches on XML data? How should i set up my xml file so
7
4548
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 records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
1
1149
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 displayed all data including Chinese simplified characters. Can anyone help me for this problem? Does anyone have any ideas for this? Kind regards,
0
1651
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 have multiple related records in 1:many relationships and many:to:many relationships. To view my results, I created a query called qryAllData which contains all of the data from several tables for each record. For example, say I have one...
2
1134
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 display all possible result like hyperlink, then user can click the hyperlink and display the detail. Is it possible? What in my mind, the only idea i have is using datagrid, display all possible result in the datagrid, which is i'm working on it, but...
5
3190
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 search algorithms that can be used are Linear Search and Binary Search. The sorting algorithms are bubble, selection and Insertion sort. First, the user is asked whether he/she wants to perform a search option, a sort operation, or exit the program. If...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.