How to bind DataGridView and add columns manually

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.
Who is Participating?
Reza RadConsultant, TrainerCommented:
0nepieceAuthor Commented:
Oh btw I'm creating a Windows Form in C# .NET 2005. I'm unable to use the BoundField here
   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

0nepieceAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.