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

The Archive Base Latest Questions

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

Hello guys i have collection : public class ActionData { private int iD; public

  • 0

Hello guys i have collection :

public class ActionData
{
    private int iD;

    public int ID 
    {
        get { return iD; }
        set { iD = value; }
    }
    private string roomType;

    public string RoomType 
    {
        get { return roomType; }
        set { roomType = value; }
    }
}

like this

private void btnGridToExcel_Click(object sender, RoutedEventArgs e)
{
    ExportExcel<ActionData, ActionDatas> exp = new ExportExcel<ActionData, ActionDatas>();
    exp.GenerateReport();
    ICollectionView view = CollectionViewSource.GetDefaultView(dataGrid1.ItemsSource);
    exp.dataToPrint = (ActionDatas)view.SourceCollection;
    exp.GenerateReport(); 
}

On this button click must export data to excel but i gives such error on exp.dataToPrint = (ActionDatas)view.SourceCollection;:

Unable to cast object of type ‘System.Collections.ObjectModel.ObservableCollection`1[H_Pro.Logicstic+ActionData]’ to type ‘ActionDatas’.

Here is a some part of method which gets values

 public class ActionDatas : List<ActionData> { }

        #region toxls
         public class ExportExcel<T, U>
        where T : class
        where U : List<T>
    {
        public List<T> dataToPrint;

does anyone have an idea why im getting such error?

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

    The data from ActionDatas might be implicitly being assigned to SourceCollection (possibly in XAML) which is an ObservableCollection<> (not the same thing as a List<>). It being an ObservableCollection is a good thing, since collection changes will automatically notify the listening WPF UI.

    You should be able to simply assign an ActionDatas, and transfer the elements:

    exp.dataToPrint = new ActionDatas();
    
    foreach(ActionData data in view.SourceCollection) {
        exp.dataToPrint.Add(data);
    }
    

    Or something along those lines.

    Update: If your datagrid ItemsSource is already an ActionDatas object, then you should assign it directly to the dataToPrint member, no need to put it in a view and then transfer back into a new collection.

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

Sidebar

Related Questions

hello guys i have this function for focus : fav[jj].setOnFocusChangeListener(new View.OnFocusChangeListener() { public int
Hello guys I have a function inside a utility class which returns the current
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Hello guys I have the following method: var usuario; usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario
Hello guys, I have an error I cannot solve, on a ASP.NET website. One
Hello guys, I have a general design problem with iPhone application. I want to
Hello guys sorry if the question looks stupid to you. i have 3 tables
Hello guys i have an website online wich access the database. The database access
Hello guys I have a question regardless a old code a client needed a
Hello guys i have installed wamp server Version 2.0 .. and i have tried

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.