Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8095729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:13:49+00:00 2026-06-05T21:13:49+00:00

In xaml, I have a listbox with a grid in it with 1 row

  • 0

In xaml, I have a listbox with a grid in it with 1 row and 2 columns. In the first column I have a name, and in the second column I have another listbox…I have the first listbox bound to an observable collection of Enclosure items. In the Enclosure class, I have another observablecollection of Servers (another class). I am trying to bind this to a listbox as well. The EnclosureID is working and updating properly as I add items to the observable collection. However, I am not so sure how to get the Slist to bind to the listbox I have within my other listbox. Anyone have any ideas? Is there another approach I can use?

    public class Enclosure
    {
        private string enclosureID; //bound to the first listbox

        //I want to bind this below to the second listbox
        //There is another class called Server with various properties
        public ObservableCollection<Server> Slist = new ObservableCollection<Server>();

        public string EnclosureID
        {
            get { return enclosureID; }
            set { enclosureID = value; }
        }
    }

In xaml:

    <ListBox x:Name="lb1" ItemsSource="{Binding}" DataContext="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <TextBlock x:Name="txtEnclosure" Text="{Binding Path=EnclosureID}" Background="Aqua" Grid.Column="0" Grid.Row="0" />
                    <ListBox x:Name="lbserver" ItemsSource="{Binding Slist}"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="1" Grid.Row="0">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock x:Name="txtServer" Text="{Binding Path=HostnameID}" Background="Beige"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

To populate lists I use this method:

            //Query the database for enclosures and populate the Enclosure observable collection in the Settings class
    public void GetEnclosures()
    {
        bool exception = false;
        Enclosure enclosure = new Enclosure();
        Server server = new Server();
        server.HostnameID = "HEY";

        OleDbCommand GetEnclosuresCommand = new OleDbCommand(Settings.GetEnclosuresQuery, Settings.conn);

        Settings.conn.Open();
        try
        {
            Settings.myReader = GetEnclosuresCommand.ExecuteReader();//begin reading
        }
        catch
        {
            MessageBox.Show("The Enclosure table is currently being used by another application. Please close the table and run this application again.");
            Settings.conn.Close();
            exception = true;
        }

        if (!exception)
        {
            // while there are enteries to retrieve
            while (Settings.myReader.Read())
            {
                enclosure.EnclosureID = Settings.myReader.GetString(0);
                enclosure.Slist.Add(server);
                Settings.Elist.Add(enclosure);
                enclosure = new Enclosure();
                server = new Server();
                server.HostnameID = "HI";
            }

            // Close when done reading.
            Settings.myReader.Close();

            // Close the connection.
            Settings.conn.Close();
        }
        else
        {
            this.NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:13:51+00:00Added an answer on June 5, 2026 at 9:13 pm

    Could be wrong, but isn’t as as simple as…

    <ListBox 
      x:Name="lbserver" 
      ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
      Grid.Column="1" 
      Grid.Row="0" 
      ItemsSource="{Binding Slist}">
    

    Also change this

    public ObservableCollection<Server> Slist = new ObservableCollection<Server>();
    

    to say

    public ObservableCollection<Server> Slist { get; set; }
    //...
    Slist = new ObservableCollection<Server>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox defined in XAML as: <ListBox x:Name=directoryList MinHeight=100 Grid.Row=0 ItemsSource={Binding Path=SelectedDirectories}/>
I have a templated ListBox : <ListBox Grid.Row=0 Grid.Column=1 Background=Transparent BorderThickness=0 x:Name=mainMenu ItemsSource={Binding Source={x:Static
I have a ListBox with the following XAML: <ListBox.ItemTemplate> <DataTemplate> <Grid Name=listItemGrid> <Grid.ColumnDefinitions> <ColumnDefinition
So I have this Xaml inside a ListBox Item Template: <ListBox.ItemTemplate> <DataTemplate> <Grid Height=22
I have a ListBox which is bound to a collection. When I add an
I have a ListBox, inside a Grid, inside an Expander. The ListBox is bound
I'm developing a Windows Phone app. I have the following XAML code: <Grid x:Name=ContentPanel
This is the xaml of listview <ListView Grid.Column=1 Height=auto Name=ListView1 Width=auto AllowDrop =True >
I have a Silverlight Listbox bound to Observablecollection which shows up fine (first time)
I have a ListBox in a file called Downloads.XAML. The items bound to that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.