List Box

  • Thread starter Thread starter DAVID STARKENBURG
  • Start date Start date
D

DAVID STARKENBURG

I am new to Programming and I would like to know if there is simple code to
populate (not sure if this is the right word) a list box with the upper case
letters A-Z and lower case letters a-z. Is there a way around having to type
each letter individually either into an array or into the items property of
the list box?
 
// Put all the uppercase letters in the listbox
int i;
for (i = 65; i<91; i++)
{
listBox1.Items.Add(Convert.ToChar(i));
}

// Put all the lowercase letters in the listbox
for (i = 97; i<123; i++)
{
listBox1.Items.Add(Convert.ToChar(i));
}

ShaneB
 
Actually, I thought of a better way (faster, simpler)
string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (int i=0; i<text.Length; i++)
{
listBox1.Items.Add(text);
}

ShaneB
 
ShaneB said:
Actually, I thought of a better way (faster, simpler)
string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (int i=0; i<text.Length; i++)
{
listBox1.Items.Add(text);
}


Except that he didn't want to type in the entire thing :)

First suggestion should work though hehe.
 
ShaneB said:
// Put all the uppercase letters in the listbox
int i;
for (i = 65; i<91; i++)
{
listBox1.Items.Add(Convert.ToChar(i));
}

// Put all the lowercase letters in the listbox
for (i = 97; i<123; i++)
{
listBox1.Items.Add(Convert.ToChar(i));
}

Small suggestion:

{
for (char c = 'A'; c <= 'Z'; ++c) {
listBox1.Items.Add(c);
}
for (char c = 'a'; c <= 'z'; ++c) {
listBox1.Items.Add(c);
}
}
 
Right...I just wanted to show him another simpler, faster, & more flexible
way of doing it. It took more keystrokes for him to post the question than
are in the code :)

ShaneB

Adam Clauss said:
ShaneB said:
Actually, I thought of a better way (faster, simpler)
string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (int i=0; i<text.Length; i++)
{
listBox1.Items.Add(text);
}


Except that he didn't want to type in the entire thing :)

First suggestion should work though hehe.
 
Back
Top