开发者

How to show some certain columns in datagridview in C#

开发者 https://www.devze.com 2023-04-08 19:34 出处:网络
After querying from database, I fill the result into dataset, suppose there are 10 columns. And then i have to show 5 of the 10 columns into datagridview.

After querying from database, I fill the result into dataset, suppose there are 10 columns.

And then i have to show 5 of the 10 columns into datagridview.

My way is to create a new DataTable with the 5 columns, and copy the value from the开发者_JAVA百科 original dataset. It works, but i don't think it's a good way.

Any suggestion?

-----------------------

I am using C# for Form Application. I prefer programic way to implement.


You can hide selected column by setting Visible to false, like datagridview.Columns[0].Visible = false


Assuming that you set the dataset as the datasource of the gridview, you can specify which columns do you want to display in the gridview by clicking on the > button in the design view and selecting edit columns.

Please see the following article: http://msdn.microsoft.com/en-us/library/ms972948.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消