Hi friends...
i have small assignement on c#
windows application to display
multiple words on textbox when u
enter in textbox suppose alphabet
"a" then it will display all words
which starting from "a" later ..
i have store all words in
arraylist..
so plz how do this ..
plz anyone telme...its urgent..
thanks and regards
shri
Loading
AlanPosted Sep 29, 2008, 10:37 AM
Well, the first thing to do is to sort the ArrayList(using the Sort() method) so that it is in alphabetical order.
If you have a lot of words in the ArrayList and the list won't change during the course of the program, then I'd be inclined to iterate through it and record in a separate array the index of the first word which begins with 'a', then 'b' and so forth. If no word begins with a particular letter, enter -1 as the index.
Consequently, when someone enters a letter in the textbox, you will be able to see immediately from your array, the index of the first word which begins with that letter and how many words there are before the next letter. You will then be able to easily fill the textbox (having set its Multiline property to true) with a list of the appropriate words retrieved from the ArrayList.
If you don't have a lot of words, then it might be easier just to search through the sorted ArrayList looking for words beginning with the appropriate letter on each query.