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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:59:38+00:00 2026-05-28T00:59:38+00:00

I have a DataGrid and two ListBoxes in my window. I am using Entity

  • 0

I have a DataGrid and two ListBoxes in my window. I am using Entity Framework to Connect to my SQL Server. Depending on the selections I make in the ListBoxes parameters will be passed to my stored procedure and data for my DataGrid will be retrieved. I was able to implement this functionality without using MVVM. I would like to know ways to implement this using MVVM. Please Help me out. Thanks in Advance.

  • 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-28T00:59:38+00:00Added an answer on May 28, 2026 at 12:59 am

    First of all, MVVM is about separating the concerns of your code into the appropriate area. For example, talking to your database via EF should be done in the Model1. The ViewModel is responsible for holding the data, and for shaping or massaging it to make it more suitable for display (i.e. transforming enums to colors2, etc).

    To implement your functionality in a MVVM way, you will need to use binding, and bind your viewmodel to your view:

    <MyControl>
        <LayoutRoot>
            <ListBox ItemsSource={Binding MyItems} SelectedItem={Binding MySelection} />
        </LayoutRoot>
    </MyControl>
    

    in the code behind for the View:

    public class MyControl
    {
        public MyControl()
        {
            this.DataContext = new MyViewModel();
        }
    }
    

    and your ViewModel will look something like this:

    public class MyViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<MyDataObject> MyItems 
        { 
            get { return _myItems; }
            set
            {
                _myItems = value;
                OnPropertyChanged("MyItems");
            } 
        }
    
        public MyDataObject MySelection { get; set; }
    
        public void DoSomethingWithDatabase()
        {
            Model.DoSomething(MySelection);
        }
    }
    

    This is just a VERY simple example to illustrate what is required if you do things the MVVM way (and I’ve deliberately missed out a bunch of stuff). To do a proper example and document all the essential bits you need to know would take at least a chapter in a book, so I’ll refer you to a MSDN article for further reading: Implementing the Model-View-ViewModel Pattern.

    1 And the Model may just be a stepping stone if you also implement SOA, the Model might just call a service which then talks to the database.
    2 This can also be done with Converters in the View, but may not always be possible or practical in a converter.

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

Sidebar

Related Questions

Can i add two header text in Datagrid? My Requirement is to have two
Im using c# .net windows form application. i have a datagrid view. It has
I have a asp:DataGrid which holds data in two columns on my webpage. The
I have a small flex datagrid. The dataProvider is an xmlList. I have two
I have two windows, a main window an a window to update the database,
I have a SL DataGrid that has two columns. I need to be able
I have a DataGrid that is used in two different views. In each case,
I have a form that consists of two data grids and a button. Datagrid
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
I have a DataGrid and two StaticResource . I want to bind RowStyle of

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.