i want to make windows application program
the program will be :
i have array contain the following values {"a",""a1,"b","b1","c","c1"}
i want to make textbox to search in the array if the user enter the frist string of element all the element which start of this character like google search
and like this pic
please send me a message
View Raw Image" href="http://i37.tinypic.com/2hed2xt.jpg" class="thickbox">
Kirtan PatelPosted Oct 16, 2009, 9:45 AM
{
col.Add(str);
}
Equavalent for loop Coding
for(int i=0;i<=array.length -1 ;i++)
{
col.Add(array[i]);
}
var is new datatype in C# 3.0 that can accept any datatype variable and make itself to like that variable datatype ( Like Object Datatype)
Here Col is Collection of String that you want to Show in AutoComplete Words List
add
Col.Add(str) will add one of the string of your array to that collection :)
if my answer helped you please mark "do you like this answer" please :)
Kirtan PatelPosted Oct 16, 2009, 10:50 AM
jkjsha ahsaPosted Oct 16, 2009, 10:44 AM
i'm very grateful to you
nice day
Kirtan PatelPosted Oct 16, 2009, 10:35 AM
its not compulsory to write code under
form()
{
}
you can also write code In Form_Load() event of the form
or in button's Click Event
here Need is that Code that make the AutoComplete Setup Once
as you can not Use TextChanged Event because TextChange event fires every time you enter character into TextBox .
and will bind the Autocomplete List that many time That is totally wrong so that can use text_changed event :-)
and when you Bind AutoComplete Source With The TextBox the procedures after that is done automatically you dont
have to manually code in text_changed event :-)
jkjsha ahsaPosted Oct 16, 2009, 10:24 AM
i under stand every word you write
i have another question
why we write this code under public form()
and not under
private void textBox1_TextChanged(object sender, EventArgs e)
i try to write the code under
private void textBox1_TextChanged(object sender, EventArgs e)
and its run some wrong way
jkjsha ahsaPosted Oct 16, 2009, 9:40 AM
jkjsha ahsaPosted Oct 16, 2009, 9:34 AM
Kirtan PatelPosted Oct 16, 2009, 9:06 AM
like we have array
string[] array = { "a", "a1", "b", "b1", "c", "c1" };
now if we want to iterate through each string in array we can use foreach
we can also use for loop to do so but for using for loop we need to know how much time the loop has to be run
in foreach we dont need to know that thing
noe lets see the code how to iterate through above show array
foreach ( string str in array)
{
// Suppose We want to add each string that is in array to listbox one by one
ListBox1.Items.Add(str);
}
That will do job efficiently.
Here in your code for AutoComplete no need to use it as we can directly add whole array in collection by AddRange()
as i shown in My above Post :-)
jkjsha ahsaPosted Oct 16, 2009, 8:58 AM
jingePosted Oct 16, 2009, 8:09 AM
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.autocompletesource.aspx
jingePosted Oct 16, 2009, 7:54 AM
AutoCompleteCustomSource property: this property is used to specify the source of the TextBox. For example, the array. But you can't simply use array directly. Since this it only accepts AutoCompleteStringCollection object. So as you see, I instatiate a new object of this type, and add the data in the array to it.
AutoCompleteMode has for enumration value:
None: does not prompt the user with dropdown, or autocomplete the word.
Suggest: only display the dropdown list, but not auto complete the word.
Append: only auto complete the word, but not show the dropdown list.
SuggestAppend: the combination of suggest and Append behavior.
You also need to specify AutoCompleteSource to CustomSource since we provide the data from the array.
If you have anything not understand, let me know.
jkjsha ahsaPosted Oct 16, 2009, 7:39 AM
or put link to article about this feature in c#
jingePosted Oct 16, 2009, 7:35 AM
Thank you.
jkjsha ahsaPosted Oct 16, 2009, 7:20 AM
jingePosted Oct 16, 2009, 7:17 AM
jingePosted Oct 16, 2009, 7:16 AM
Don't forget to accept this post as answer if it solves your problem.
jkjsha ahsaPosted Oct 16, 2009, 7:14 AM
Kirtan PatelPosted Oct 16, 2009, 7:10 AM
Here is Code How to do that
don't forget to mark "do you like this answer " please it will give me credits :)
private void Form1_Load(object sender, EventArgs e)
{
string[] array = { "a", "a1", "b", "b1", "c", "c1" };
//Create AutoComplete Collection
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
//Add Array Values to that Collection
collection.AddRange(array);
// Set TextBox Properties
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource = collection;
}