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

  • Home
  • SEARCH
  • 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 8760101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:57:43+00:00 2026-06-13T14:57:43+00:00

I am a C++ developer and just started working on WPF. Following MVVM, I

  • 0

I am a C++ developer and just started working on WPF. Following MVVM, I am working on comboboxes where I have to add items in it. Well adding items in it seems to be quite easy but I have come across a simple issue where I am not able to figure out what to do. Here is the code:

XAML:

<ComboBox Grid.Row="0" ItemsSource="{Binding DaughterBoardBoxList}" SelectedItem="{Binding SelectedDaughterBoardBoxList, Mode=TwoWay}" SelectedIndex="0" />
<ComboBox Grid.Row="1" ItemsSource="{Binding DaughterVersionBoxList}" SelectedItem="{Binding SelectedDaughterVersionBoxList, Mode=TwoWay}" SelectedIndex="0" />
<ComboBox Grid.Row="2" ItemsSource="{Binding DaughterSerialBoxList}" SelectedItem="{Binding SelectedDaughterSerialBoxList, Mode=TwoWay}" SelectedIndex="0" />

ViewModel Class:

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

    public string _SelectedDBoardBoxList;
    public string SelectedDaughterBoardBoxList
    {
        get { return _SelectedDBoardBoxList; }
        set
        {
            _SelectedDBoardBoxList = value;
            OnPropertyChanged("SelectedDaughterBoardBoxList");
        }
    }

// Similarly for other 2 comboboxes

I have added items in each combobox as follows:

  • DaughterBoardBoxItems = “S1010013”, “S1010014”, “S1010015” etc
  • DaughterVersionBoxItems = “001A”, “001B”, “001C” etc
  • DaughterSerialBoxItems = 1 to 499

I Have added from 1 – 499 as follows:

for (int j = 1; j < 500; j++)
{
      _DSerialBoxList.Add(j.ToString());
} 

Now on performing some operation I need to execute few statements which are as follows:

String daughterBoard = "S1010015001A0477"; // Hardcoded value for check
String boardName = daughterBoard.Substring(0, 8);
DaughterBoardBoxList = boardName;

String version = daughterBoard.Substring(8, 12);
DaughterVersionBoxList = version;

int serialvalue = Convert.ToInt32(daughterBoard.Substring(12, 16));
String serialNo = Convert.ToString(serialvalue);
DaughterSerialBoxList = serialNo;

longlabel += daughterBoard;

When I execute the above code, it throws me exception at String version = daughterBoard.Substring(8, 12); as Argumentoutofrange. Index and length must refer to a location within the string.

Requirement:

  • Now this where I am confused how do I set the values present in boardName, version and serialNo in the combobox without having to face any exception. I don think combobox has settext property. Is their an other alternative solution to achieve this?

  • Even though I enter values from 0 to 499, it should appear as 4 digit value i.e. if 77 is added, it should appear as 0077. As I have mentioned in the above code.

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-13T14:57:44+00:00Added an answer on June 13, 2026 at 2:57 pm

    Firstly the exception is coming because you are stepping out of the string bounds.

    String version = daughterBoard.Substring(8, 4)

    ..is what you are after, there isn’t 12 characters available after the 8th. The second parameter is the length you require from the first parameter, not the start.

    Then do a check to see if the string is in the list.

    if (DaughterVersionBoxList.Contains(version))
    {
         SelectedDaughterVersionBoxList = version;
    }
    

    Setting the SelectedDaughterVersionBoxList will apply it to the combobox.

    A two way binding, as you have done with the selected item, is the best way to set the selected item of a listbox.

    There a a couple of ways to format the text you wish to display. Sometimes you can use the StringFormat attribute in xaml. The other is to use a converter.

    The shortcut in your case would be to format your string as you populate the list.

    for (int j = 1; j < 500; j++)
    {
          _DSerialBoxList.Add(j.ToString("D4"));
    } 
    

    That will make sure you always get 4 digits in your Combobox. Look here for more info on it. If the situation required you to actually process the list items as numeric values then you would be better off converting your ObservableCollection to ObservableCollection and using a converter as I mentioned before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Being a somewhat proficient iOS developer, I have just started working on a desktop
I am a C++ developer and have recently started learning WPF. I am working
I have just started to develop the form below and I have the following
I just started working at a place as a front end developer where I
I am an windows developer with over 15 years experience. I have just started
I've just started working for a new firm as an in-house web developer. Up
I have just started working with a new company in a very small IT
I just started working in a WPF project using a Ribbon Bar, but I
I've just started working on servlets and i'm a newbie. I have developed a
I am a new developer in Android. Currently I have started working on 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.