datagridview binding and object properties

B

brianlanning

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?

brian
 
B

brianlanning

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?

brian



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

brian
 
R

RobinS

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

brian

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

[System.ComponentModel.BrowsableAttribute(false)]

RobinS.
GoldMail, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top