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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:05:29+00:00 2026-05-15T03:05:29+00:00

I have datagrid with list of MyPlayer objects linked to ItemsSource, there are ComboBoxes

  • 0

I have datagrid with list of MyPlayer objects linked to ItemsSource, there are ComboBoxes inside of grid that are linked to a list of inner object, and binding works correctly: when I select one of the item then its value is pushed to data model and appropriately updated in other places, where it is used.

The only problem: initial selections are not displayed in my ComboBoxes. I don’t know why..?

Instance of the ViewModel is assigned to view DataContext. Here is grid with ComboBoxes (grid is binded to the SquadPlayers property of ViewModel):

    <data:DataGrid ="True" AutoGenerateColumns="False" ItemsSource="{Binding SquadPlayers}">
        <data:DataGrid.Columns>
            <data:DataGridTemplateColumn Header="Rig." Width="50">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox SelectedItem="{Binding Rigid, Mode=TwoWay}"
                                  ItemsSource="{Binding IntLevels, Mode=TwoWay}"/>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
        </data:DataGrid.Columns>
    </data:DataGrid>

Here is ViewModel class (‘_model_DataReceivedEvent’ method is called asynchronously, when data are received from server):

public class SquadViewModel : ViewModelBase<SquadModel>
{
    public SquadViewModel()
    {
        SquadPlayers = new ObservableCollection<SquadPlayer>();
    }

    private void _model_DataReceivedEvent(List<SostavPlayerData> allReadyPlayers)
    {
        TeamTask task = new TeamTask { Rigid = 1 };
        foreach (SostavPlayerData spd in allReadyPlayers)
        {
            SquadPlayer sp = new SquadPlayer(spd, task);
            SquadPlayers.Add(sp);
        }
        RaisePropertyChanged("SquadPlayers");
    }

And here is SquadPlayer class (it’s objects are binded to the grid rows):

public class SquadPlayer : INotifyPropertyChanged
{
    public SquadPlayer(SostavPlayerData spd)
    {
        _spd = spd;

        Rigid = 2;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private int _rigid;
    public int Rigid
    {
        get { return _rigid; }
        set
        {
            _rigid = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Rigid"));
            }
        }
    }

    private readonly ObservableCollection<int> _statIntLevels = new ObservableCollection<int> { 1, 2, 3, 4, 5 };
    public ObservableCollection<int> IntLevels { get { return _statIntLevels; } }

It is expected to have all “Rigid” comboboxes set to “2” value, but they are not selected (items are in the drop-down list, and if any value is selected it is going to ViewModel).

What is wrong with this example? Any help will be welcome.

Thanks.

  • 1 1 Answer
  • 2 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-15T03:05:30+00:00Added an answer on May 15, 2026 at 3:05 am

    Change the order of your XAML to

    ItemsSource="{Binding IntLevels, Mode=TwoWay}" 
    SelectedItem="{Binding Rigid, Mode=TwoWay}"
    

    I know it seems funny but I have had this problem before. It is attempting to bind the SelectedValue before the ItemSource exists, which is why after the initialization everything works.

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

Sidebar

Related Questions

I have a datagrid that displays a list of custom objects. This list contains
I have a custom dataGrid that acts more like a 2D list (if that
I have a Silverlight 2.0 DataGrid that contains a list of items that needs
I have a datagrid with a list of JobItem objects, and when I select
I have such DataGrid <DataGrid AutoGenerateColumns=True HorizontalAlignment=Stretch Name=dataGrid1 VerticalAlignment=Stretch ItemsSource={Binding DataList} IsReadOnly=True/> In my
I have a DataGrid view that fill it's content by a list in run
I have an ajax datagrid that displays a list of items in the customer's
I have a datagrid, bound to a List: <DataGrid HorizontalAlignment=Left SelectedItem={Binding CurrentPlayer} Height=374 Margin=121,22,0,0
I have a dataGrid bound to a List object and this works fine by
I have a WPF Datagrid binded with list of interface objects. Consider, ClsEmployee class

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.