Hey guys, i figured out how to add items to a listbox one line at a time:
try
{
if (nameTxtbox.Text == "")
throw new Exception();
listBox1.Items.Add(nameTxtbox.Text);
nameTxtbox.Text = "";
textBox1.Text = "";
nameTxtbox.Focus();
}
catch(Exception err)
{
MessageBox.Show(err.Message, "Enter something into the txtbox", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
But I wont to be able to add multiple items to the same line. Like have first_name | last_name | DoB all on the same line. When I do
listBox1.Items.Add(last_name.Text);
It adds the last name to a new line on the listbox, I need to add it to the same line as the first name.
It sounds like you still want to add one "item", but you want it to contain more than one piece of text. Simply do some string concatenation (or using
string.Format
), eg.Usually you don't want to include multiple columns into a
ListBox
, because ListBox is meant to have only one column.I think what you're looking for is a ListView, which allows to have multiple columns. In a ListView you first create the columns you need
Here has a solution to add multiples items at the same time.
Hope this can help.