A to Z buttons

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
 
S

Smithers

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!
 
C

cody

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
}
 
G

Guest

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!
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top