从 MultiSelect ListBox 获取 TextBox 中 SelectedItems 的选定值(用逗号分隔)?

Get Selected Value of SelectedItems in a TextBox (separated with Commas) from MultiSelect ListBox?

请告诉我如何获得 ValueMember of ListBox SelectedItems?我已经阅读了很多教程,但仍然无法解决。任何帮助将不胜感激。

int c = subjects_Listbox.Items.Count - 1;
for (int i = 0; i >= 0; i--)
{
    if (subjects_Listbox.GetSelected(i))
    {
        txt.Text += subjects_Listbox.SelectedIndices[i].ToString();
        txt.Text += ", ";
    }
}

您的 for 循环不正确。试试这个(遍历所有 ListBoxSelectedIndices 并将它们添加到你的 TextBox):

foreach (var item in subjects_Listbox.SelectedIndices)
{
     txt.Text += item;
     txt.Text += @", ";
}

甚至更好:

txt.Text = string.Join(",", subjects_Listbox.SelectedIndices.Cast<int>());