简体   繁体   中英

ListBox SelectedItems to MessageBox

I have little problem with show string in MessageBox. I load date from database into ListBox.

Now I want show selecteditem. I have something like this:

StringBuilder message = new StringBuilder();
foreach (var selectedItem in CategorylistBox.SelectedValue.ToString())
{
    message.AppendLine(selectedItem.ToString());
}
MessageBox.Show(message.ToString());

I select "Sci-Fi" movie category, but I get:

http://prnt.sc/dvmfyl

Can someone help me and tell how to display it in one line?

On AddMovieClick please comment every thing else and test this one it will show you current items selected .

if (CategorylistBox.SelectedItems != null)
{
    foreach (var item in CategorylistBox.SelectedItem.ToString())
    {
        Debug.WriteLine("current item "+item);
        // CinemaDataSetTableAdapters.QueriesTableAdapter kTyp = new CinemaDataSetTableAdapters.QueriesTableAdapter();
        // kTyp.AddCategoryType((selectedItem), TitleTextBox.Text);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM