datagridview binding and object properties

  • Thread starter Thread starter brianlanning
  • Start date Start date
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
 
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
 
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.
 
Back
Top