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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:50:52+00:00 2026-06-13T12:50:52+00:00

I am a C++ developer and have recently started learning WPF. I am working

  • 0

I am a C++ developer and have recently started learning WPF. I am working on a wpf app where I am using MVVM. I have comboboxes and I need to add items in it. Although I generally use ComboboxPropertyName.Add(“”) to add items in it, I am looking for an efficient method which adds the items without much code length. Here is the code:

XAML:

<ComboBox Height="23" ItemsSource="{Binding BoardBoxList}" SelectedItem="{Binding SelectedBoardBoxList, Mode=TwoWay}" SelectedIndex="0" Name="comboBox2" />

ViewModel Class:

public ObservableCollection<string> BoardBoxList
    {
        get { return _BoardBoxList; }
        set
        {
            _BoardBoxList = value;
            OnPropertyChanged("BoardBoxList");
        }
    }

    /// <summary>
    /// _SelectedBoardBoxList
    /// </summary>
    private string _SelectedBoardBoxList;
    public string SelectedBoardBoxList
    {
        get { return _SelectedBoardBoxList; }
        set
        {
            _SelectedBoardBoxList = value;
            OnPropertyChanged("SelectedBoardBoxList");
        }
    }

Here Is how I had added items in my combobox in C++:

static const signed char boards[][9] = {
{},                                           // left blank to indicate no selection
{ 'S', '1', '0', '1', '0', '0', '1', '2', 0 },   // redhook
{ 'S', '1', '0', '1', '0', '0', '1', '8', 0 },   // bavaria
{ 'S', '1', '0', '1', '0', '0', '2', '0', 0 },   // flying dog
};

m_boardBox = new ComboBox(String::empty);
for(int i = 1; i < 4; i++)
    m_boardBox->addItem(String((char*)(boards[i])), i); 
m_boardBox->setSelectedId(2); // select Bavaria by default
addAndMakeVisible(m_boardBox);

If you notice above, you will find the loop adding items easily. This is how i wanna add items to my combobox.

If I use _BoardBoxList.Add("...."); I will have to use many .Adds. Is their an efficient way where I can store the items in a list/collection and add them into the combobox in the form of for loop just like above?

Please help 🙂

  • 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-13T12:50:53+00:00Added an answer on June 13, 2026 at 12:50 pm

    You can use a constructor of ObservableCollection that can consume an enumerable as a start set.

    new ObservableCollection<string>(boards);
    

    Boards would have to be an collection of strings not chars.

    Edit:

    var boards = new[]{ "S1010012" ,   // redhook
                       "S1010018",   // bavaria
                       "S1010020"    // flying dog
                      } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a C++ developer and recently started working on WPF. I am sorry
I have recently started having a need to start learning Java Script. My application
I've been a web developer for some time now, and have recently started learning
I have recently started learning C++ and coming from a Ruby environment I have
I'm a front end developer who's recently started using IntelliJ Idea for JS development.
I'm a junior developer and recently started working for a very small office where
I have recently started my job as web application backend developer. I am bit
I have an app that I developed with Xcode 3 and recently started editing
We have recently started using git and had a nasty problem when someone committed
I have recently started working on some open source project which I found relevant

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.