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

  • Home
  • SEARCH
  • 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 7824417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:35:25+00:00 2026-06-02T08:35:25+00:00

I have a class, ExpenseItem and a list based off that class. I’m currently

  • 0

I have a class, ExpenseItem and a list based off that class.

I’m currently designing a form that has a combo box that would allow me to select a particular type of ExpenseItem Trip, and show all results in a listbox.

Form Code (tripSelect is the combo box and listExpenses is the list box):

    private void LoadExpenseList()
    {
        tripSelect.Items.Clear();
        var dateSorted =
            from e in roster
            group e by e.Trip into tripGroup
            select new { Trip = tripGroup.Key };
        foreach (var e in dateSorted)
            tripSelect.Items.Add(e.Trip);
    }

    private void LoadExpenseDetail()
    {
        listExpenses.Items.Clear();
        var dateSorted =
            from e in roster
            orderby e.Trip
            select e;
        foreach (var e in dateSorted) ;
    }

    private void ExpenseRecorderForm_Load(object sender, EventArgs e)
    {

    }

    private void tripSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        selectedExpense = (ExpenseItem)roster.ToFind((string)tripSelect.SelectedItem);
        listExpenses.Items.Add(selectedExpense);
    }


    private void listExpenses_SelectedIndexChanged(object sender, EventArgs e)
    {
        tripTextBox.Text = selectedExpense.Trip;
        tripTextBox.Enabled = false;
        descriptionTextBox.Text = selectedExpense.Description;
        amountTextBox.Text = selectedExpense.Amount.ToString();
        paymentMethodTextBox.Text = selectedExpense.PaymentMethod;
        dateExpenseTimePicker.Value = selectedExpense.Date;
        dateExpenseTimePicker.Enabled = true;
        noteTextBox.Text = selectedExpense.Note;
    }
  • 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-02T08:35:26+00:00Added an answer on June 2, 2026 at 8:35 am

    I can’t code something like myVariable.Where(); since it’s not IEnumerable

    I don’t really understand by what you mean with this.

    As for the error, it says you can’t cast from the IEnumerable to ExpenseItem. You have to apply it like you final example like so and return the item rather than IEnumerable. I would just skip the Where clause and go straight into using FirstOrDefault

    public ExpenseItem ToFind(string trip)
    {
        return this.FirstOrDefault(e => e.Trip == trip);
    }
    

    I presume this is a custom made collection otherwise the Linq extensions won’t work on this

    EDIT

    If you really want this..

    public IEnumerable<ExpenseItem> ToFind(string trip)
    {
        return this.Where(e => e.Trip == trip);
    }
    

    Then you will need to deal with the list from the caller.

    private void tripSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        IEnumerable<ExpenseItem> selectedExpenses = roster.ToFind((string)tripSelect.SelectedItem);
        foreach(ExpenseItem item in selectedExpenses)
            listExpenses.Items.Add(item);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class A and list of A objects. A has a function f
I have class B that has class A, this is simplified version of class
I have class User that contains protected constructor and class Account that has access
I have class which has a method that needs to return three DataTables. I
I have class, that has a NSString. @interface AudioManager : NSObject { AudioData *data_;
I have class method that returns a list of employees that I can iterate
I have class A that has some primitive attributes and also member of type
Alright, I have a class EIR which is a List based from its base
I have class that represents users. Users are divided into two groups with different
I have class ParentClass that observes an NSNotification. ParentClass handles the notification. ChildClass inherits

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.