• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

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.
0
0nepiece
Asked:
0nepiece
  • 2
2 Solutions
 
0nepieceAuthor Commented:
Oh btw I'm creating a Windows Form in C# .NET 2005. I'm unable to use the BoundField here
0
 
MathiyazhaganCommented:
Hi,
   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

0
 
0nepieceAuthor Commented:
Thanks!
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now