A to Z buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am creating an inventory program, I would like to know how to create A to Z
buttons on runtime and than save data to the letter. Like if I hit F I will
get all the names that start with F
 
You really need to tell us more about what you are trying to do. Where is
your data saved. "...get all the names that start with F..." Get from where?
A Database? An XML file? A Web service? A Flat file? Memory?

Help us help you!
 
for (char l = 'A'; l<='Z'; l++)
{
Button b = new Button();
b.Text = l.ToString();
myForm.Controls.Add(b);
// set the location of the button here
// and add an eventhandler for the click event
}
 
the data will be saved to an access db

Smithers said:
You really need to tell us more about what you are trying to do. Where is
your data saved. "...get all the names that start with F..." Get from where?
A Database? An XML file? A Web service? A Flat file? Memory?

Help us help you!
 
Hi,

Do this :

Create a new class ButtonEx : Button
{
char letter;
ButtonEx( char whatLetter){ letter = whatLetter; }
}

then create as many controls as you need :
// CODE TAKEN FROM cody's post
for (char l = 'A'; l<='Z'; l++)
{
ButtonEx b = new ButtonEx( l);
b.Text = l.ToString();
b.OnClick = new EventHandler( letterButton_Clicked); /// <<=== the real
thing
myForm.Controls.Add(b);
}

void letterButton_Clicked( object sender ... )
{
//cast the sender to the new button
ButtonEx clicked = ( ButtonEx) sender;
//access the char
clicked.Letter;
//do as needed
}


cheers,
 
Back
Top