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 7190011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:25:24+00:00 2026-05-28T19:25:24+00:00

I have a collection of StackPanel which each one includes a dynamic set of

  • 0

I have
a collection of StackPanel which each one includes a dynamic set of controls (based on database values), I want to set them as ItemsSource of some ComboBox
for example i have two database values which should be generated:

In DB i have these:
row 1=>Class [a] p [B] , [AB]vb
row 2=>Class tpy rbs=[sdfg],kssc[h] hm

and each one should generate as a ComboBox column like the fallowing:

In ComboBox I wanna generate these :
 ComboBoxItem 1 :Class [a textBox] p [a textBox] , [a textBox]vb
 ComboBoxItem 2 :Class tpy rbs=[a textBox].kssc[a textBox] hm

the fallowing code is doing this right:

Class ConvertToControlsFormat()
{
    Regex exp = new Regex(@"\[\w*\]");
    var source = new TestEntities().cmbSources;
    foreach (var item in source)
    {
        StackPanel p = new StackPanel { Orientation = Orientation.Horizontal, FlowDirection = FlowDirection.LeftToRight };
        int i = 0;
        foreach (string txt in exp.Split(item.Title))
        {
            p.Children.Add(new TextBlock { Text = txt });
            if (i < exp.Matches(item.Title).Count)
                p.Children.Add(new TextBox { Text = exp.Matches(item.Title)[i].Value, Width = 30 });
        }
        cmb.Items.Add(p);
    }
}

But I cant set TwoWay DataBindings for that, so I created a list of StackPanel as a field of cmbSource class (which is bound to ItemsSource of the ComboBox)

public partial class cmbSource
{
    #region Primitive Properties
    int iD;

    public virtual int ID
    {
        get
        {
            if (Title != null)
                ControlsCollection = SetControlsCollection(Title);
            return iD;
        }
        set
        {
            iD = value;

        }
    }

    private StackPanel SetControlsCollection(string ttl)
    {
        Regex exp = new Regex(@"\[\w*\]");
        StackPanel p = new StackPanel { Orientation = Orientation.Horizontal, FlowDirection = System.Windows.FlowDirection.LeftToRight };
        int i = 0;
        foreach (string txt in exp.Split(ttl))
        {
            p.Children.Add(new TextBlock { Text = txt });
            if (i < exp.Matches(ttl).Count)
                p.Children.Add(new TextBox { Text = exp.Matches(ttl)[i].Value, Width = 30 });
        }
        return p;
    }

    public virtual string Title
    {
        get;
        set;
    }

    public virtual StackPanel ControlsCollection
    {
        get;
        set;
    }

    #endregion
}

but I have no idea of how bind it to ItemsSource of my ComboBox

Summery:I want to bind a list of controls to a ComboBox
any suggestions!? thank you.

  • 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-05-28T19:25:25+00:00Added an answer on May 28, 2026 at 7:25 pm

    EDIT

    First: you do not bind a ComboBox to a collection of UI Elements. That is not the way WPF works. Container controls such as the Grid, StackPanel and Canvas can contain child controls. ItemsControls such as the ComboBox contain data objects and use DataTemplates to display the items.

    Secondly: if the database can contain ANY data that could cause ANY UI to be needed you will need to generate the UI in code by creating StackPanels etc. adding controls and bindings as you do in your code examples.

    Thirdly: the reason you can’t bind is that the data from the database is a string that you split into parts; there is no way you can simply go back to the string.

    Suggestion: the string in the database is probably (I hope) in some sort of format. Using that knowledge you could generate a new format string when you are parsing the database string. E.g., when the database contains foo [bar] you could generate {0} [bar]. On a save action from the user you could use that string to create the updated string for the database by using: String.Format("{0} [bar]", someControl.Text)

    Extra: Please, next time, use better names and example texts; the question is unreadable like this. There is no way you can expect us to understand 2=>Class tpy rbs=[sdfg],kssc[h] hm

    OLD ANSWER

    Make a class Stuff, implementing INotifyPropertyChanged and having the properties Name and Value.

    Load the database data into an ObservableCollection<Stuff> and bind the ComboBox to this collection.

    Set the ItemTemplate of the combo box to a datatemplate like this:

    <ComboBox ItemsSource="{Binding}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name}"/>
                    <TextBox Text="{Binding Value}"/>
                </StackPanel>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined one Thickness resource in Window's resources collection which is set to
I'm a little puzzled with this one. I have a Collection called AllProducts, which
I have Collection List<Car> . How to compare each item from this collection with
I'm planning to have collection of items stored in a TCollection. Each item will
I have a collection of objects to which I'd like to just add a
We have a collection of commercial MFC/C++ applications which we sell using Stingray Objective
I have a collection of classes that I want to serialize out to an
I have a collection of Boost unit tests I want to run as a
I have a collection of unmanaged dlls with a C# wrapper around them that
I have a ListBox which is bound to a collection. When I add an

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.