Hi guys-
I am a beginner in C#, and I am writing a very simple application. I basically want two text box's, textBox1, and textBox2. The user writes a list in textBox1, and the list is displayed with some formatting in textBox2.
12345667 '12345667',
12345668 '12345668',
12345669 '12345669',
12345670 '12345670'
I have tried a number of different ways. My biggest hope was putting txtBox1.Text in a string, and splitting it with a regex of ("\n"). I thought it was going to work, but when I do that Regex, it does not remove the "\n" so I cannot add ' right after the split string. Instead it looks something like this:
'12345667
','12345668....
Can someone write me a small code example of an effective way to take the list out of the left text box, format it, and display in text box 2?
Thanks guys!
Stephen
Loading
StephenPosted Apr 28, 2007, 2:53 PM
Thanks for all the help,
Stephen
Richard BlythePosted Apr 28, 2007, 11:32 AM
If you are wanting to create a formatted list, my advice would be to use a listbox. It will serve the same functionality as a multiline textbox but with a Whole lot more control on each line.
Why don't you try this?
Add one textbox to your form. Name it txtLine
Add one listBox to your form. Name it LstItems
Add two buttons to your form. Name them: btnAdd, btnRemove
Now switch to code view and paste this code
private void btnAdd_Click(object sender, EventArgs e)
{
//Only add if the are some text in the textbox
if (txtLine.Text != "")
LstItems.Items.Add(txtLine.Text);
}
private void btnRemove_Click(object sender, EventArgs e)
{
//Only remove if there is an item selected
if (LstItems.SelectedIndex != -1)
LstItems.Items.Remove(LstItems.SelectedIndex);
}
Important! You will need to go to design mode and link the button event handlers to this code. Look at the window where you edit properties and find the lightning bolt. That is where you add or link events.
Hope it helps!
Richard