473,554 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.FindString implementation

Hello!

I have recently come across two very nice methods in ListBox control:
..FindString and .FindStringExac t
it is very usefull for me, and I would like to use it in some other
situations.

Where could I find an implementation of thiese methods or other similar
solutions. I would like to use such methods without ListBox - only with a
simple
Collection like SortedList (key and value). I have created a simple
implementation myself but I'm not sure it's that quick.

SortedList searchList = new SortedList();

// [...] - fill the list
foreach (DictionaryEntr y de in searchList) {

string strKey = (string) de.Key;

if (strKey.StartsW ith(strSearched )) {

return de.Value; break;

} else {

if (strKey.Compare To(strSearched) > 0) break;

}

}
Marcin Floryan
marcin at floryan dot neostrada dot pl
Nov 16 '05 #1
1 2763
Marcin,

This is not as fast as it could be. What I would do is get the keys,
and then perform a binary search on it. Basically, since the keys should be
ordered (it is a sorted list, right), you can basically use a binary search.

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

"Marcin Floryan" <marcin[REMOVE]@floryan.neostr ada.pl> wrote in message
news:O%******** ********@TK2MSF TNGP15.phx.gbl. ..
Hello!

I have recently come across two very nice methods in ListBox control:
.FindString and .FindStringExac t
it is very usefull for me, and I would like to use it in some other
situations.

Where could I find an implementation of thiese methods or other similar
solutions. I would like to use such methods without ListBox - only with a
simple
Collection like SortedList (key and value). I have created a simple
implementation myself but I'm not sure it's that quick.

SortedList searchList = new SortedList();

// [...] - fill the list
foreach (DictionaryEntr y de in searchList) {

string strKey = (string) de.Key;

if (strKey.StartsW ith(strSearched )) {

return de.Value; break;

} else {

if (strKey.Compare To(strSearched) > 0) break;

}

}
Marcin Floryan
marcin at floryan dot neostrada dot pl

Nov 16 '05 #2

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

Similar topics

0
1065
by: Rene Aguirre | last post by:
Hello everybody, I had this problem using the FindString funcion of a wxChoice object on wxPython: * I have Windows 98 * I read a text file edited on a Japanese computer, but only uses 'english' characters. * From the file I loaded some strings in some wxChoice object. * Later when I wanted to find an string using 'FindString' I never...
17
3093
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
9
4626
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
2
2061
by: Jorge | last post by:
Hello I have a little problem i have a checkedlistbox with several repeated items. The code below only selects the first ocurrence While reader.Read For i = 0 To Me.CheckedListBox1.Items.Count - 1 Me.CheckedListBox1.SetItemChecked (Me.CheckedListBox1.FindString(reader.GetString(0)), True)
0
1581
by: commanderjason | last post by:
I am converting a .net winforms app to wpf I make use of the System.Windows.Forms.ComboBox.FindString but am unable to find anything that accomplishes that in the System.Windows.Controls.ComboBox Currently I have to iterate through each item and check them manually. I'm thinking there must be a better way, but the msdn docs seem to fall...
0
7611
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...
0
7535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7812
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. ...
0
7894
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...
0
5162
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...
0
3579
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...
0
3561
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2026
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
850
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...

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.