How to bind DataGridView and add columns manually

Posted on 2009-12-28
Last Modified: 2013-12-17
Hi everyone, I created a Base DataGirdView control that will contain existing records depending on a transaction. I'm using C# .NET 2005. How do I bind data from MS Access 2003 and select columns to be added in the datagridview manually? Thanks in advance.
Question by:0nepiece
    LVL 30

    Accepted Solution


    Author Comment

    Oh btw I'm creating a Windows Form in C# .NET 2005. I'm unable to use the BoundField here
    LVL 10

    Assisted Solution

       First fill the dataset/datatable with MS-Access Query.then, you can populate the grid like following code :
    dgvSample.AutoGenerateColumns = false;
                DataTable dt = GetSampleData();
                //dgvSample.Columns.Add (tableColumnname,header display text
                dgvSample.Columns.Add(dt.Columns[0].ColumnName, dt.Columns[0].ColumnName);
                dgvSample.Columns.Add(dt.Columns[1].ColumnName, dt.Columns[1].ColumnName);
                dgvSample.Columns.Add(dt.Columns[2].ColumnName, dt.Columns[2].ColumnName);
                dgvSample.Columns.Add(dt.Columns[3].ColumnName, dt.Columns[3].ColumnName);
                dgvSample.Columns.Add(dt.Columns[4].ColumnName, dt.Columns[4].ColumnName);

    Open in new window


    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now