开发者

Windows Forms Listbox Multible Lists in same Box

开发者 https://www.devze.com 2023-03-05 15:23 出处:网络
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

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 an开发者_如何转开发d 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


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.


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消