Click here to Skip to main content
Licence CPOL
First Posted 21 Feb 2011
Views 7,144
Downloads 249
Bookmarked 5 times

Phone Index

By | 21 Feb 2011 | Article
This is a program for phone index to see how we can use the alphabetical English characters (A..Z) to search a customer name which begin with any character.
 
Part of The SQL Zone sponsored by
See Also

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

// Create and set (26) buttons for English Characters:

private void CreateButtons()
{
    int xPos = 0;
    int yPos = 0;
    // assign number of buttons = 26
    btnArray = new System.Windows.Forms.Button[26]; 
    // Create (26) Buttons:
    for (int i = 0; i < 26; i++)
    {
        // Initialize one variable
        btnArray[i] = new System.Windows.Forms.Button(); 
    }
    int n = 0;
    while(n < 26)
    { 
        btnArray[n].Tag = n + 1; // Tag of button
        btnArray[n].Width = 24; // Width of button
        btnArray[n].Height = 20; // Height of button
        if(n == 13) // Location of second line of buttons:
        {
            xPos = 0;
            yPos = 20;
        }
        // Location of button:
        btnArray[n].Left = xPos; 
        btnArray[n].Top = yPos; 
        // Add buttons to a Panel:
        panel1.Controls.Add(btnArray[n]); // Let panel hold the Buttons
        xPos = xPos + btnArray[n].Width; // Left of next button
        // Write English Characters:
        btnArray[n].Text = ((char)(n + 65)).ToString();
        // the Event of click Button:
        btnArray[n].Click += new System.EventHandler(ClickButton);
        n++;
    }
}
// Result of the event click Button, get the text of button and find record: 

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); //using (DataReader) to find records
}

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mostafa Kaisoun



Egypt Egypt

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralParameters. Pinmemberjw12322:30 21 Feb '11  
GeneralRe: Parameters. PinmemberMostafa Kaisoun11:54 22 Feb '11  
GeneralLayout. PinmemberJefis22:09 21 Feb '11  
GeneralRe: Layout. PinmemberMostafa Kaisoun11:54 22 Feb '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 22 Feb 2011
Article Copyright 2011 by Mostafa Kaisoun
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid