0

I'm working on a project where I'm getting a list of contacts from a webservice. These contacts have names and emails and each of thoose I save in a list of strings. Now I want my listbox to take in the names and the emails and write them in 2 columns. Then I want to be able to select one set in the listbox and get the email or name in that set. My problem is I cant find a method for doing the multicolumn thing. The only thing I've found is the Listbox.MultiColumn attribute but it seems to take 1 list and just divide it into more columns.

Thanks in advance

2 Answers2

0

You can use DataGridView
You can add rows like this:

string[] row1 = new string[] { "Column 1", "Column 2", "..." };
string[] row2 = new string[] { "Column 1", "Column 2", "..." };
// And so on
object[] rows = new object[] { row1, row2 };

foreach (string[] row in rows)
{
    yourDataGridView.Rows.Add(row);
}
opekope2
  • 48
  • 7
0

ListBoxes don't support multiple columns (MultiColumn just spreads the existing items across columns, as you have seen)

An alternative would be to use a ListView set in Details mode instead, and add each column as a SubItem as in this question.

Community
  • 1
  • 1
stuartd
  • 70,509
  • 14
  • 132
  • 163