Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a data table in c# windows application
and i have add two columns to this datagridview (colItemCode,colDescription)

now i want to bind this datagrideview with sql data table call ITEM_MASTER

Special thing is i want to add the table filed (itCode,itDescription, these are SQL table field) To two columns call (colItemCode,colDescription) in datagridview in windows form application

how to do this
thak you
Posted
Comments
PRAKASH9 25-Nov-14 1:25am    
you can apply datasource property of datagridview like grid.DataSource = datatable;

Hello ,
Similar Requirement I Faced Some Months Back.So i Achieved with The Help Pf Following Steps
1) First Retieve The Table From DataBase.
2) Add The Column into That DataTable
3) Bind The Datatable To The GRid View.

To Add The Columns into The Data Table
Assumption: you have declared a DataTable Object as dt
C#
dt.Columns.Add("colItemCode");
dt.Columns.Add("colDescription");


After this Bind The GridView
C#
dataGridView1.DataSource = dt


It will display the columns added in the added table
[If you insert some data into dt,then write dt.AcceptChanges();]

Hope It Solves Your Problem
Happy Coding
:-)
 
Share this answer
 
C#
dataGridView1.DataSource = ITEM_MASTER;
dataGridView1.Columns[0].DataPropertyName = "itCode";
dataGridView1.Columns[1].DataPropertyName = "itDescription";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900