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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:56:47+00:00 2026-05-27T19:56:47+00:00

I have the following code: private void EntryBrowserLoad(object sender, EventArgs e) { var ase

  • 0

I have the following code:

    private void EntryBrowserLoad(object sender, EventArgs e)
    {
        var ase = new AprilShowersEntities();

        var q =
            from d in ase.Entries
            orderby d.EntryEndTime
            select d;

        var dateQuery = from d in q.AsEnumerable()
                        select new
                        {
                            d.EntryEndTime,
                            d.EntryId,
                            d.EntryPlainText,
                            d.EntryStartTime,
                            d.EntryText,
                            EntryHeader = GetEntry(d.EntryEndTime, d.EntryPlainText)
                        };

        lcEntries.DisplayMember = "EntryHeader";
        lcEntries.DataSource = dateQuery;
    }

    private void BtnOkClick(object sender, EventArgs e)
    {
        var q = (Entry) lcEntries.SelectedItem.Value; // Error here on this line

        MessageBox.Show(q.EntryText);
    }

My problem is its getting an error on the line marked above, complaining about not being able to cast the object back into an Entry object. The reason, I’m sure, is because I’m using select new in my LINQ query. My question is, how can I read the EntryText property of the returned SelectedItem.Value object?

  • 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-27T19:56:48+00:00Added an answer on May 27, 2026 at 7:56 pm

    You are projecting into an anonymous type. To reference the result elsewhere (outside of the context of the containing method) with compile-time safety and features such as Intellisense, you need to project into a concrete type. If you do not already have such a class, then define a class that describes your element

    class TheEntry { /* define properties */ }
    

    Then select into the class with your query

    select new TheEntry 
    

    And then you can cast to that that class

    var entry = (TheEntry)lcEntries.SelectedItem.Value;
    

    It is generally preferred to define a proper type once you start passing a query result around or need access to it outside of its containing method. However, you can technically bypass this by using dynamic or runtime binding, as well. I would not recommend it, but it is an available approach.

    dynamic entry = lcEntries.SelectedItem.Value;
    MessageBox.Show(entry.EntryText); // no compile-time support, purely runtime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private void button1_Click(object sender, EventArgs e) { var answer
I have the following code: SaveFileDialog saveGC1File = new SaveFileDialog(); private void GCSavePlacementOneButton_Click(object sender,
I have the following code- private void button1_Click(object sender, EventArgs e) { _soundplayer.Play(); timer1_Tick();
I have the following code: private void button1_Click(object sender, EventArgs e) { Process process
I have following code: private void fileSystemWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) { System.Diagnostics.Process execute =
i have following code ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadAsync), apiMethod); downloadHandle.WaitOne(); Where DownloadAsync is private void DownloadAsync(object
I have the following code: private void Package_ContactDown(object sender, ContactEventArgs e) { ScatterViewItem svi
I have a datagridview with the following code: private void datagridview_CustomerList_CellEndEdit(object sender, DataGridViewCellEventArgs e)
I am work with SharpPcap library. I have following code: private void button1_Click(object sender,
I have the follwing code (which is not working): private void Window_PreviewKeyDown(object sender, KeyEventArgs

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.