locked
add all of listbox items to another listbox RRS feed

  • Question

  • Hi,

    i have to listboxes and i want to add all of first listbox items to second listbox

    thanks for your help.

    Wednesday, July 31, 2013 8:15 PM

Answers

  • Ok Ehsan Azami,

    listBox2.Items.AddRange(listBox1.Items);

    There you go brother!

    • Proposed as answer by Magnus (MM8)MVP Thursday, August 1, 2013 8:50 AM
    • Marked as answer by Caillen Wednesday, August 7, 2013 5:12 AM
    Thursday, August 1, 2013 8:45 AM
  • Hi Ehsan,

    You can just set the same item source of the first listbox to the secod listbox as below.

    listBoxSecond.ItemsSource = listBoxFirst.ItemsSource;

    ------------------------------------------------------------------------------

    Please mark as "Answered" / Vote if response solves your problem

    • Proposed as answer by Shailendra Damodare Friday, August 2, 2013 6:46 AM
    • Marked as answer by Caillen Wednesday, August 7, 2013 5:12 AM
    Friday, August 2, 2013 6:42 AM

All replies

  • You can use

    ListBox1.Items.Insert(indexNumber, "item")

    ListBox2.Items.Insert(indexNumber, liVariable);

    ListItem liVariable = ...

    Wednesday, July 31, 2013 8:37 PM
  • Ok Ehsan Azami,

    listBox2.Items.AddRange(listBox1.Items);

    There you go brother!

    • Proposed as answer by Magnus (MM8)MVP Thursday, August 1, 2013 8:50 AM
    • Marked as answer by Caillen Wednesday, August 7, 2013 5:12 AM
    Thursday, August 1, 2013 8:45 AM
  • if (ListBox1.SelectedItems.Count > 0)
    {
    DataTable sourceTable = ListBox1.DataSource as DataTable;
    if (sourceTable != null)
    {
    int index = ListBox1.SelectedIndex;
    ListBox2.Items.Add(sourceTable.Rows[index][ListBox1.DisplayMember].ToString());
    sourceTable.Rows.RemoveAt(index);
    }
    }


    Kind regards, Brus

    Thursday, August 1, 2013 8:52 AM
  • Hi Ehsan,

    You can just set the same item source of the first listbox to the secod listbox as below.

    listBoxSecond.ItemsSource = listBoxFirst.ItemsSource;

    ------------------------------------------------------------------------------

    Please mark as "Answered" / Vote if response solves your problem

    • Proposed as answer by Shailendra Damodare Friday, August 2, 2013 6:46 AM
    • Marked as answer by Caillen Wednesday, August 7, 2013 5:12 AM
    Friday, August 2, 2013 6:42 AM