Water Cooler v2
Water Cooler v2

Reputation: 33850

Hide columns in a DataGridView

Let's say I have a table like so:

Friend
------
Id int not null
FriendName nvarchar(50) not null
Phone nvarchar(50) null

If I bind my DataGridView control in a Windows Forms application to an ObjectQuery<Friend>/ObjectSet<Friend>/IList<Friend> returned from an ObjectContext like so:

MyFriendsGridView.DataSource = _context.Friends.ToList();

All the columns that are in the Friend table appear in the grid. Suppose I want the Id column not to show up in the grid, how do I do that?

Do I simply hide the column in the grid's properties by setting the column's visibility to false? Is there a more elegant solution?

Upvotes: 1

Views: 2242

Answers (1)

JPReddy
JPReddy

Reputation: 65503

Setting column's visible property to false is the elegant solution as far as I know.

Upvotes: 1

Related Questions