How to bind selected columns to datagridview at runtime.
I have written select * from tableName. And result i have stored in DataTable dt. Now i want only selected columns to be displayed in datagridview at runtime. I dont want to bound gridview at designtime.

Recommended Answers

Do you need all of the columns out of the database or could you just select only the ones you need? Most of the time SELECT * isn't really needed.
If not, you can bind various columns of your gridview to the columns of the data source in code. This …

Jump to Post

All 4 Replies

Actuly i can write only required column name but my query is parameterized and cloumn which i am using for parameter that i dont wont to display

And other columns i am binding with other labels so thats why i have to do * option.

Thanks hericles its working.
All i have done is instead of writing DataGridViewTextBoxColumn i have written DataGridViewColumn. And DataGridViewColumn's obj.CellTemplate = new DataGridViewTextBoxCell(); because DataGridViewTextBoxColumn do not have DataPropertyName property.
Thank you your link was helpfull

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.