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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:47+00:00 2026-05-28T04:04:47+00:00

I am using WPF MVVM Pattern. I have 2 ListBoxes and a DataGrid in

  • 0

I am using WPF MVVM Pattern. I have 2 ListBoxes and a DataGrid in my view. I am using EntityFramework to get data from SQL Server. My ViewModel looks like this

    private Types _type;
    private Users _user;
    private ObjectResult<APP> _dataContext;

    public IEnumerable<Types> Categories
    {
        get;
        private set;
    }

    public IEnumerable<Users> SystemNames
    {
        get;
        private set;
    }

    public Types SelectedType
    {
        get
        {
            return _type;
        }
        set
        {
            _type = value;
            RaisePropertyChanged("SelectedType");
        }
    }       

    public Users SelectedUser
    {
        get
        {
            return _user;
        }
        set
        {
            _user = value;
            RaisePropertyChanged("SelectedUser");
        }
    }

    public ObjectResult<APP> DContext
    {
        get
        {
            return _dataContext;
        }
        set
        {
            _dataContext = value;
            RaisePropertyChanged("DContext");
        }
    }

    public ObjectResult<APP> GetDataContext()
    {
        AppLogEntities context = new AppLogEntities();
        return context.GetAppLog(SelectedUser.User, SelectedType.Type);
    }

    public DetailsViewModel()
    {
        Categories = new List<Types>
        {
            new Types{Type = "All"},
            new Types{Type = "Information"},
            new Types{Type = "Warning"},
            new Types{Type = "Error"}
        };

        SystemNames = new List<Users>
        {
            new Users{User = "All"},
            new Users{User = "SYS_01"},
            new Users{User = "SYS_02"}
        };

        SelectedType = new Types();
        SelectedUser = new Users();

        DContext = GetDataContext();
    }`

And my View liiks like this

<Window x:Class="SingleAppLogMVVM.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:SingleAppLogMVVM"
    Title="MainWindow" Height="800" Width="1000">
<Window.DataContext >
    <vm:DetailsViewModel />
</Window.DataContext>
<Grid>
    <ListBox Height="200" HorizontalAlignment="Left" Margin="50,50,0,0" Name="fTypeListBox" VerticalAlignment="Top" Width="125" SelectionMode="Single" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedType, Mode=TwoWay}" >
        <ListBox.ItemTemplate >
            <DataTemplate >
                <DockPanel Width="120" LastChildFill="True" >
                    <TextBlock Text="{Binding Type, Mode=TwoWay}" Width="110" Margin="5" />
                </DockPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <ListBox Height="Auto" HorizontalAlignment="Left" Margin="50,275,0,50" Name="fUserListBox" VerticalAlignment="Stretch" Width="125" SelectionMode="Single" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding SystemNames}" SelectedItem="{Binding SelectedUser, Mode=TwoWay}"  >
        <ListBox.ItemTemplate >
            <DataTemplate >
                <DockPanel Width="120" LastChildFill="True" >
                    <TextBlock Text="{Binding User, Mode=TwoWay}" Width="110" Margin="5" />
                </DockPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <DataGrid AutoGenerateColumns="False" Height="350" HorizontalAlignment="Stretch" Margin="225,50,50,0" IsReadOnly="True" Width="Auto"
              VerticalAlignment="Top" CanUserReorderColumns="False" CanUserResizeColumns="False" Name="fDGrid"  VirtualizingStackPanel.IsVirtualizing="True"
              CanUserResizeRows="False" IsManipulationEnabled="True" RowHeight="35" SelectionMode="Single" VirtualizingStackPanel.VirtualizationMode="Recycling"
              ItemsSource="{Binding DContext, Mode=OneWay}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" Width="5*" />
            <DataGridTextColumn Header="IID" Binding="{Binding Path=IID}" Width="5*" />
            <DataGridTextColumn Header="INSTANCEID" Binding="{Binding Path=INSTANCEID}" Width="10*" />
            <DataGridTextColumn Header="TYPE" Binding="{Binding Path=TYPE}" Width="10*" />
            <DataGridTextColumn Header="SOURCE" Binding="{Binding Path=SOURCE}" Width="10*" />
            <DataGridTextColumn Header="TIME" Binding="{Binding Path=TIME}" Width="10*" />
            <DataGridTextColumn Header="SNAME" Binding="{Binding Path=SNAME}" Width="10*" />
            <DataGridTextColumn Header="MESSAGE" Binding="{Binding Path=MESSAGE}" Width="15*" />
            <DataGridTextColumn Header="ACTIONS" Binding="{Binding Path=ACTIONS}" Width="15*" />
            <DataGridTextColumn Header="CLEARED ON" Binding="{Binding Path=CLEAREDON}" Width="10*" />
        </DataGrid.Columns>
    </DataGrid>        
</Grid>

I am able to get my LisBoxes populated. And also I am able to get my DataGrid populated if a plugin values manually in my ViewModel code

 public ObjectResult<APP> GetDataContext()
    {
        AppLogEntities context = new AppLogEntities();
        return context.GetAppLog(SelectedUser.User, SelectedType.Type);
    }

I don’t understand why it isn’t working based on my selection from ListBoxes. Please help me out.

  • 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-28T04:04:48+00:00Added an answer on May 28, 2026 at 4:04 am

    a couple small changes are required to get the results you are after

    public Types SelectedType
    {
        get
        {
            return _type;
        }
        set
        {
            _type = value;
            RaisePropertyChanged("SelectedType");
            DContext = GetDataContext(); //refresh the data
        }
    }       
    
    public Users SelectedUser
    {
        get
        {
            return _user;
        }
        set
        {
            _user = value;
            RaisePropertyChanged("SelectedUser");
            DContext = GetDataContext(); //refresh the data
        }
    }
    
    
    public DetailsViewModel()
    {
        Categories = new List<Types>
        {
            new Types{Type = "All"},
            new Types{Type = "Information"},
            new Types{Type = "Warning"},
            new Types{Type = "Error"}
        };
    
        SystemNames = new List<Users>
        {
            new Users{User = "All"},
            new Users{User = "SYS_01"},
            new Users{User = "SYS_02"}
        };
    
        _type = new Types();  //use the field rather than the property so GetDatacontenxt doesnt get called multiple times
        _user = new Users();
        DContext = GetDataContext();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I am coding a WPF application using MVVM pattern. I don't need to have
I have a WPF Microsoft Surface Application and I'm using MVVM-Pattern. I have some
I'm playing with my first wpf project using the mvvm pattern. I have Microsoft
I'm using the MVVM pattern in my first WPF app and have a problem
In a WPF app that I'm writing using the MVVM pattern, I have a
I am developing an application in WPF using the MVVM pattern. If I have

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.