Groups | Blog | Home
all groups > dotnet windows forms > february 2008 >

dotnet windows forms : datagridview binding and object properties



brianlanning
2/13/2008 12:39:05 PM
Suppose I have an object that looks like this:

public class thing
private mOne as string
private mTwo as string
private mThree as string
private mFour as string

public property one as string
bla
end property

(and so on, public properties for the others)

end class

then I make a List(of Thing) and add a bunch of instances

then I bind the list to a datagridview

It's not possible for me to make the properties private

My problem is that I only want to display properties One and Two in
the grid view. I want Three and Four around to help out with sorting
and data type conversion, but I don't want to display them in the
grid. Currently, I just remove the columns programmatically. But
what I really want is to decorate the properties with attributes that
affect which properties appear in the grid. Does such an attribute
exist?

brianlanning
2/13/2008 8:55:18 PM
[quoted text, click to view]



Looks like the DataGridView.CellFormatting event was made for this.
Works great.

RobinS
2/14/2008 11:23:36 PM

[quoted text, click to view]

That's one way. Also adding this attribute above the property name will
help:

[System.ComponentModel.BrowsableAttribute(false)]

RobinS.
GoldMail, Inc.
AddThis Social Bookmark Button