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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:55:15+00:00 2026-06-10T16:55:15+00:00

Working On Simple Entity Frame Work sample with Combo Box . i am trying

  • 0

Working On Simple Entity Frame Work sample with Combo Box . i am trying to populate datagridview on the basis of combo Box selections but i am getting casting error

I have Simple MDF database and i used database first to generate model for EF .
in EF , NiftyFO is a model consists of TradId, StrikePrice , VolumeTraded etc ..

        NiftyEntities nf = new NiftyEntities();
        NiftyFO nfo = new NiftyFO();

        nfo = (NiftyFO)(comboBox1.SelectedItem);

         var result = from x in nf.NiftyFOes
                     where x.StrikePrice ==nfo.StrikePrice
                     select x;
        dataGridView1.DataSource = result;
        dataGridView1.Refresh();

And the exact error it showing wheni change ComboBox Seletion is

 Unable to cast object of type '<>f__AnonymousType0`1[System.Nullable`1[System.Decimal]] 
     to type 'agileLocal.NiftyFO.'

and

Combo Box Filled with Strike Price and loaded from the databse throgh the ef and code goes like this

             NiftyEntities nf = new NiftyEntities();
          var result2 = from x in nf.NiftyFOes
                          select new { x.StrikePrice };
            //comboBox1.DisplayMember = "StrikePrice";
            comboBox1.DataSource = result2;

Solved :

select new { x.StrikePrice }; 

i just changed this line

select x.StrikePrice . and it worked .

  • 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-10T16:55:17+00:00Added an answer on June 10, 2026 at 4:55 pm

    then your code will be

       decimal myselected = (decimal)(comboBox1.SelectedItem);
    
    
     var result = from x in nf.NiftyFOes
                     where x.StrikePrice == myselected 
                     select x;
        dataGridView1.DataSource = result;
        dataGridView1.Refresh();
    

    because in your select new { x.StrikePrice }; you are selecting the StrikePrice and not the object it self

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

Sidebar

Related Questions

I'm currently working on a simple php function for an entity in the framework
I'm trying to make a simple text editor with winapi, its working for simple
I am working on a simple web application made using Entity Framework 4.1 Code
I am starting to know and work with Entity Framework. And I am trying
I am working to create a simple CRUD application in WPF which will work
I am working with Entity Framework Code first. I have a simple model: public
I'm trying to get server-side validation of an Entity Framework String Property to work.
This should be a really simple problem to solve, but for some reason Entity
The simple working query, list the number of licenses for each license type: Query:
Good Day, I have a simple working routine in Perl that swaps two words:

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.