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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:18:05+00:00 2026-05-28T11:18:05+00:00

i have Devxpress GridControl on the form, and i want to send data on

  • 0

i have Devxpress GridControl on the form,
and i want to send data on this grid to excel.
and i dont want to do this with ExportToExcel method
i have googled and found this code
but this code is for DataGrid control of .Net
and it gives an error when it tries to convert
DevExpress.XtraGrid.Views.Grid.GridView to System.Data.DataView
here is the code

public string LastCoulmLetter(int coulmnCount)
{
        string finalColLetter = string.Empty;
        string colCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int colCharsetLen = colCharset.Length;

        if (coulmnCount > colCharsetLen)
        {
            finalColLetter = colCharset.Substring(
                (coulmnCount - 1) / colCharsetLen - 1, 1);
        }

        finalColLetter += colCharset.Substring(
                (coulmnCount - 1) % colCharsetLen, 1);

        return finalColLetter;
}


public void FromGridToExcel()
{
        if (gridView1.RowCount <= 0)
            return;
        Excel.Application xls = new Excel.Application();
        Excel.Workbook wb;
        Excel.Worksheet sheet;

        object SalakObje = System.Reflection.Missing.Value;
        wb = xls.Workbooks.Add(SalakObje);
        sheet = (Excel.Worksheet)wb.ActiveSheet;
        sheet.Name = "Result";
        xls.Visible = true;

        DataTable dt = (DataTable)gridView1.DataSource; // Error comes in here

        // Copy the DataTable to an object array
        object[,] rawData = new object[dt.Rows.Count + 1, dt.Columns.Count];

        // Copy the column names to the first row of the object array
        for (int col = 0; col < dt.Columns.Count; col++)
        {
            rawData[0, col] = dt.Columns[col].ColumnName;
        }

        // Copy the values to the object array
        for (int col = 0; col < dt.Columns.Count; col++)
        {
            for (int row = 0; row < dt.Rows.Count; row++)
            {
                rawData[row + 1, col] = dt.Rows[row].ItemArray[col];
            }
        }

        // Fast data export to Excel
        string excelRange = string.Format("A1:{0}{1}",LastCoulmLetter(dt.Columns.Count), dt.Rows.Count + 1);

        sheet.get_Range(excelRange, Type.Missing).Value2 = rawData;

        sheet.get_Range(excelRange).Columns.AutoFit();
}

So what is the problem and how to fix it

  • 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-28T11:18:06+00:00Added an answer on May 28, 2026 at 11:18 am

    The problem appears to be that your DataSource is a DataView, not a DataTable.

    Some options:

    Cast it to a DataView if you want to use the same filters:

    DataView dv = (DataView)gridView1.DataSource;
    

    Use the .Table property to get the source table if you want the raw data:

    DataTable dt = ((DataView)gridView1.DataSource).Table;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have GridControl (DevExpress) of form. I want to call some method when position
I have a devexpress.XtraVerticalGrid.VGridControl, I have two columns on this grid. Column1 is a
I currently have the following XAML for my Grid control: <dxg:GridControl x:Name=DXGrid> <dxg:GridControl.Columns> <dxg:Column
I have a grid (DevExpress XtraGrid, if that matters) which is bound to a
I need to create a Firebird Database programmatically using DBExpress. I have done this
VB .NET 4 WinForms application. I have a (DevExpress) grid bound to an IEnumerable(Of
i have web form running in asp.net & c#.net, The form has a devexpress
I want to standardize the behaviour on an Devexpress TcxGrid. So I have a
I have a C# WinForms application. This exception is thrown within the static void
I've recently overridden the DevXpress WPF grid to give myself a SelectedObject property that

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.