0

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?

Daniel
  • 9,491
  • 12
  • 50
  • 66
adamo ski
  • 17
  • 7
  • can you print value of message on command line and check if message has some content in it , – Yashveer Singh Jan 14 '17 at 18:54
  • or try listBox1.SelectedItem.ToString() may be it will help Please let me know if it work I will post it as answer – Yashveer Singh Jan 14 '17 at 18:56
  • i have added sample code please check if it work please mark my answer – Yashveer Singh Jan 14 '17 at 19:05
  • @YashveerSingh I try foreach (var selectedItem in KategorialistBox.SelectedItems.ToString()) but I get: http://prnt.sc/dvmtl8 – adamo ski Jan 14 '17 at 19:18
  • The question is where in which event you are doing it ? also is listbox support multiple selection of not . can you please paste complete source code so that I can help. – Yashveer Singh Jan 14 '17 at 19:21
  • @YashveerSingh Here is all I get: https://drive.google.com/file/d/0B_aqF-0bbuILMlQ0V2ZyZENYLWc/view?usp=sharing – adamo ski Jan 14 '17 at 19:28
  • ok and which function you are trying to get selected items and which listbox ? – Yashveer Singh Jan 14 '17 at 19:33
  • I try it in (private void AddMovieButton_Click(object sender, EventArgs e)) ListBox > CategorylistBox I try: CategorylistBox.SelectedItems.ToString() and CategorylistBox.SelecteValue.ToString() – adamo ski Jan 14 '17 at 19:39
  • check my answer .if you comment all code and just run this code on inside the button click it will show you all item which you selected in CategorylistBox . Output will be deisplay on output window please try – Yashveer Singh Jan 14 '17 at 20:03
  • If someone have similar problem here is solution: [http://stackoverflow.com/questions/16778180/listbox-selected-item-give-me-system-data-datarowview-c-sharp-winforms](http://stackoverflow.com/questions/16778180/listbox-selected-item-give-me-system-data-datarowview-c-sharp-winforms) – adamo ski Jan 15 '17 at 17:47

1 Answers1

0

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);
    }
}
Daniel
  • 9,491
  • 12
  • 50
  • 66
Yashveer Singh
  • 1,914
  • 2
  • 15
  • 23
  • I'm sorry but unfortunately, I do not know how to implement the code. I'm noobie ;) – adamo ski Jan 14 '17 at 19:23
  • that is not a issue I will help please show me you source code . – Yashveer Singh Jan 14 '17 at 19:24
  • Unfortunately this WindowsFormAplication and Debug.WriteLine doesn't work. – adamo ski Jan 14 '17 at 20:26
  • ok then show in messagebox or debug it u can see values when you degug it – Yashveer Singh Jan 14 '17 at 20:29
  • If I use MessageBox.Show("Current item " + item); I get: http://prntscr.com/dvo0ar the i click OK and I have next MessageBox with "Current item y" All letters: System.Data.DataRowView i check too: StringBuilder message = new StringBuilder(); foreach (var selectedItem in KategorialistBox.SelectedItems) { message.AppendLine(selectedItem.ToString()); } MessageBox.Show(message.ToString()); http://prntscr.com/dvo1oh – adamo ski Jan 14 '17 at 20:40
  • ok very sttange cant help more . do u have team viewer installed i can connect to ur machine nd chk – Yashveer Singh Jan 14 '17 at 20:47
  • OK, thank you. I found something like this and it's work for one select item: string selected = this.KategorialistBox.GetItemText(this.KategorialistBox.SelectedItem); MessageBox.Show(selected); but I don't know how to display more then one value :/ – adamo ski Jan 14 '17 at 20:59