I can't found solution... i have set 4 columns in DataGrid view but when i am using SqlDatAdapter and DataTable it displaying all columns .
I have 10 columns in table, but i want to display only 4 columns in datagrid in c#, how can i do it?
Asked
Active
Viewed 472 times
3 Answers
4
This happens when the AutoGenerateColumns property is set to true (which is the default value). To turn it off, set AutoGenerateColumns to false.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autogeneratecolumns.aspx

Babak Naffas
- 12,395
- 3
- 34
- 49
1
First, set GridView's property AutoGenerateColumns=false
. During database connectivity, select only the four columns that you are needed and fill the DataAdapter with the DataTable. Then it will work.

thevan
- 10,052
- 53
- 137
- 202
0
What Babak Naffas said and you need to define your columns of the items that you want to show instead...
see: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.aspx
There is an example toward the end of the article that show how to do this.

Jimmy Chandra
- 6,472
- 4
- 26
- 38