Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Visual Studio 2010 WPF and ListBoxes

Visual Studio 2010 WPF and ListBoxes

Scheduled Pinned Locked Moved WPF
csharpvisual-studiowpf
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RossouwDB
    wrote on last edited by
    #1

    Good day, I wan't to ask something that is obvious to do in VS 2005 and VS 2008 (WPF), but for some reason, I am struggling my but of in VS 2010 (WPF). :wtf: I want to dynamically load items into a ListBox, but for some reason it does not want to show up in the ListBox, they are there (I perform a count on the ListBox, and it shows the expected number). Here is how I do it: First of, I add an item like this: this.lstItems.Items.Add(OtherStackPanel(temp));, where OtherStackPanel is a function that returns a populated stackpanel, with the following items: 1 x Label, 1 x TextBox, 1 x ComboBox, 3 x Seperator, 1 x Slider, which look as follows

    __________________________________________________________________________
    | | | | | | | |
    |ComboBox | Seperator | Label | Seperator | TextBox | Seperator | Slider |
    |__________|___________|_______|___________|_________|___________|________|

    This would then be added to the ListBox, all the items in the StackPanel are set to be visible, and they have a parent since they are added to the StackPanel. After I have added the StackPanel, I call the LayoutUpdated event of the ListBox, to make sure that they are contained in the ListBox, but I also add two addisional items from within this eventhandler, as follows:

    private void listBox1_LayoutUpdated(object sender, EventArgs e)
    {
    if (sender != null)
    {
    ListBoxItem l = new ListBoxItem();
    l.Content = "S";
    ListBoxItem n = new ListBoxItem();
    n.Content = "A";
    ((ListBox)sender).Items.Add(l);
    this.lstItems.Items.Add(n);
    MessageBox.Show(((ListBox)sender).Name);
    MessageBox.Show(Convert.ToString(((ListBox)sender).Items.Count));
    }
    }

    ((ListBox)sender).Name returns ListBox, which is correct, since the item passed to this event is that listbox, and ((ListBox)sender).Items.Count returns 3, which is correct, since I have added the StackPanel, "S" and "A", but for some odd reason, I cannot see the items in the ListBox. I have tried this.lstList.Items.Insert(0, "S"), but to no avail! If you could provide a possible solution, I would really appreciate it (I don't know why it is so much different than VS 2008 WPF). :confused: I am using Windows 7 Ulitmate. Kind Regards, Rossouw :)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups