Introduction
I wrote an article earlier to create Array
of PictureBox
and wrote another article to create Array
of Label
and TextBox
controls. You can also read the easy code to create Array
of twenty-six buttons for alphabetical English characters A..Z. Now, in this article, I shall use the twenty-six buttons idea to write a program for phone index to see how we can use the alphabetical English characters (A..Z) to search a customer name which begins with any character, also you can read about some methods of ADO.NET.
Background
I create two projects, I write code of one under C# and write another under VB. The code in this article will be under C#, you can read my two projects after you expand the files:
- MyPhone_C#.zip
- MyPhone_VB.zip
Using the Code
private void CreateButtons()
{
int xPos = 0;
int yPos = 0;
btnArray = new System.Windows.Forms.Button[26];
for (int i = 0; i < 26; i++)
{
btnArray[i] = new System.Windows.Forms.Button();
}
int n = 0;
while(n < 26)
{
btnArray[n].Tag = n + 1;
btnArray[n].Width = 24;
btnArray[n].Height = 20;
if(n == 13)
{
xPos = 0;
yPos = 20;
}
btnArray[n].Left = xPos;
btnArray[n].Top = yPos;
panel1.Controls.Add(btnArray[n]);
xPos = xPos + btnArray[n].Width;
btnArray[n].Text = ((char)(n + 65)).ToString();
btnArray[n].Click += new System.EventHandler(ClickButton);
n++;
}
}
private void ClickButton(Object sender, System.EventArgs e)
{
Button btn = (Button) sender;
string strFind = btn.Text + "%";
string strSql = "SELECT * FROM Phone WHERE [Name] LIKE " +
"'" + strFind + "'" + " Order by Name";
FindAnyName(strSql);
}
Remarks
After you extract the files (*.zip), you can read the remaining code about using ADO methods and see the result when running the program.
Final Words
I hope this article is useful. If you have any ideas, please tell me. Thanks to CodeProject and thanks to all.
Mostafa Kaisoun
m_kaisoun@hotmail.com
History
- 21st February, 2011: Initial version