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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:01:59+00:00 2026-06-06T09:01:59+00:00

I’ve got an MVVM application that uses Entity Framework 4.1, WPF and C#. I

  • 0

I’ve got an MVVM application that uses Entity Framework 4.1, WPF and C#. I am trying to get it so that when I double click a row in from a datagrid (the grid binds to an EntitySet in my DataBase named LoanComparisons) in a view I’ve got called LoanListingView, it switches over to my other view (named LoanCalculatorView) passing the information in my database (EntitySet named Loans) by the information given in the row that was selected.

So far I’ve already wired the app so double clicking a row in LoanListingView DataGrid opens up LoanCalculatorView that has default values that have been entered into it’s fields.

Now for some code. Here is my DataGrid that binds to my database entity set named LoanComparisons:

       <DataGrid MouseDoubleClick="OnDoubleClick"  ItemsSource="{Binding Path=LoanComparisons}" 
                  AutoGenerateColumns="False" SelectionChanged="DataGrid_SelectionChanged">

            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" Header="Customer Name" Binding="{Binding Path=Name}" />
                <DataGridTextColumn IsReadOnly="True" Header="Home Value" Binding="{Binding Path=HomeValue}" />
                <DataGridTextColumn IsReadOnly="True" Header="Monthly Income" Binding="{Binding Path=MonthlyIncome}" />
                <DataGridTextColumn IsReadOnly="True" Header="First Payment" Binding="{Binding Path=FirstPaymentDate}" />
            </DataGrid.Columns>
        </DataGrid>

Double clicking any row opens up my LoanCalculatorView with pre-set values. Currently the DoubleClick event runs this code:

      /// Handles double-clicks on datagrid rows
    private void OnDoubleClick(object sender, MouseButtonEventArgs e)
    {
        if (sender != null)
        {
            DataGrid grid = sender as DataGrid;
            if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
            {
                DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
              _viewModel.Open(null);


              //The DataContext will be set to dgr but since "DataGridRow"
              //does not contain the Open method I cant do this:
              //  DataContext = dgr;
              //dgr.Open(dgr);
              //
              //I think this is where I am lost at

            }
        }
    }

Currently, the Open method passes a null value into it’s method because I’m not sure how to pass the information from my other EntitySet named “Loans”. The open method is as follows:

//Creates a new LoanCalculatorViewModel that calls the SetComparisonDataRecord method
//passing it an argument comparison and changes the DataContext to LoanCalculatorView.
  public void Open(LoanComparison comparison)
  {
     var loanCalculatorViewModel = new LoanCalculatorViewModel();

     loanCalculatorViewModel.SetComparisonDataRecord(comparison);

     var loanCalculatorView = new LoanCalculatorView {DataContext = loanCalculatorViewModel};

     loanCalculatorView.Show();
  }

Finally, the SetComparisonDataRecord right now simply is empty but I put a comment of what should be in there and how I want to set the values:

      public void SetComparisonDataRecord(LoanComparison comparison)
  {


     //SharedValues.HomeValue = comparison.HomeValue;

  }

One other thing to keep in mind, my two EntitySets have a one-to-many relationship. One loan and a collection of LoanComparisons. Is it possible to show me how to pass the information from the selected row (representing an Entity from my LoanComparisons EntitySet) to the LoanCalculatorView?

  • 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-06T09:02:01+00:00Added an answer on June 6, 2026 at 9:02 am

    Changed my OnDoubleClick Method like so, where the DataContext gets set in the Open method:

     private void OnDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (sender != null)
            {
                DataGrid grid = sender as DataGrid;
                if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
                {           
                    var lc = grid.SelectedItem as LoanComparison;
                    if (lc != null) _viewModel.Open(lc);
    
                }
            }
        }
    

    simple open method:

    public void Open(LoanComparison comparison)
      {
         var loanCalculatorViewModel = new LoanCalculatorViewModel();
    
         loanCalculatorViewModel.SetComparisonDataRecord(comparison);
    
         var loanCalculatorView = new LoanCalculatorView {DataContext = loanCalculatorViewModel};
    
         loanCalculatorView.Show();
      }
    

    From there I wrote a basic query asking my database for the “loan” entity:

    public void SetComparisonDataRecord(LoanComparison comparison)
               {
    
         var calcEntities = new LoanCalcEntities();
    
         var currentLoan = from loan in calcEntities.Loans
                           where loan.LoanId == comparison.CurrentLoanId
                           select loan;
    
    
         var proposedLoan = from loan in calcEntities.Loans
                           where loan.LoanId == comparison.ProposedLoanId
                           select loan;
    
         //SharedValues.HomeValue = comparison.HomeValue;
    
      }
    

    Sorry for the trouble! Thanks for the help 🙂

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.