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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:45:21+00:00 2026-05-30T09:45:21+00:00

my DataTable has over 1000 columns and I want to display values on the

  • 0

my DataTable has over 1000 columns and I want to display values on the datagridview. Because of the FillWeigth problem I use the following method to fill the gridview,

public bool TransferDataTableToGrid(DataGridView dataGrid, DataTable dataTable)
    {
        dataGrid.SuspendLayout();

        if ((dataGrid != null) && (dataTable != null))
        {
            dataGrid.Columns.Clear();
            dataGrid.AutoGenerateColumns = false;
            dataGrid.DataSource = dataTable;

            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                DataGridViewColumn column = new DataGridViewColumn();
                column.Name = dataTable.Columns[i].ColumnName;
                column.FillWeight = 1;
                column.CellTemplate = new DataGridViewTextBoxCell();
                column.ValueType = dataTable.Columns[i].DataType;
                dataGrid.Columns.Add(column);
            }
            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                for (int ii = 0; ii < dataTable.Rows.Count; ii++)
                {
                    dataGrid[i, ii].Value = dataTable.Rows[ii][i];
                }
            }
        }
        dataGrid.ResumeLayout();
        return true;
    }

and sometimes I have an effect that my gridview is empty. Only after second execution data is displayed. Do you have any ideas, why…?

Thanks.

  • 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-30T09:45:23+00:00Added an answer on May 30, 2026 at 9:45 am

    Well, I solved my problem. With Ivan’s suggestion I tried the alternative way to fill data: instead of using DataSource I add new rows manually

                foreach (DataRow row in dataTable.Rows)
                {
                    var dataGridRow = new DataGridViewRow();
                    dataGridRow.CreateCells(dataGrid);
    
                    for (int i = 0; i < row.ItemArray.Length; i++)
                    {
                        dataGridRow.Cells[i].Value = row.ItemArray[i];
                    }
    
                    dataGrid.Rows.Add(dataGridRow);
                }
    

    …and it works – data in dgv is displayed. Thanks!

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

Sidebar

Related Questions

I have a DataTable which is bound to DataGridView . DataTable has several columns
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I have a simple Parallel.Foreach loop that has about 1000 rows in the DataTable,
say I display a datatable on a datagridview, then the user sorts it, and
Consider My dynamically generated datatable contains the following fileds Id,Name,Mob1,Mob2 If my datatable has
I'm trying to use LINQ to iterate over the rows in a DataTable, and
My Datatable has some columns that contains data in the format as 2011~|~2012~|~2013. Now
The DataTable has a method called ImportRow(), There is also a method unders the
I have a datatable I'm using which has 5 columns ( http://datatables.net/ ) The
I have a data table which already has some values, plus it is getting

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.