Okai, let’s say we have:
- 2 Textboxes (textBox1, textBox2)
- 1 Button (button1)
- A List (list1)
What I’m trying to do is to store the text that has been entered in textBox1 to list1 so I can easily retrieve my previous input. The text from textBox1 will be written to list1 when I press the button. this is the code that I have so far:
private static List<string> list1 = new List<string>();
list1.Add(textBox1.Text); // <-- On the button click event.
private void ServerInputtextboxCommand_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
foreach (var usedCommand in list1)
{
textBox1.Text = usedCommand;
}
break;
}
}
So I’m trying to get the text I’ve entered in textBox1 back to textBox1 with the arrow up key.
The text I enter in textBox1 will be shown in textBox2 (but this isn’t relevant here).
Thanks for all who want to help me, because I don’t know what I’m doing wrong :(.
I suggest using a
Stack<T>– it will be easier to track.You can then use something like this:
if you want a redo option then you can have a redo stack as well.