views:

152

answers:

3

I have a custom collection let's say

MyClass
{
    prop Name;
    prop Address;
    prop isRequired;
}


MyCustomCollection : List<MyClass>
{

}

When I do

MyCustomCollection collection = new  MyCustomCollection ();
datagridView.DataSource = collection;

The datagridview is populated with three columns Name, address , isRequired..

I want to hide isRequired property from the datagrid view how can i do that...

and also I want to use it as a property to check in another classes...

+1  A: 

I used [Browsable(false)]

MyClass {
prop Name; prop Address; [Browsable(false)] prop isRequired; } to hide the column

Ashish Ashu
+1  A: 

the Browsable attribute is a good option indeed. You could also set AutoGenerateColumns to false and create the columns manually...

Thomas Levesque
Thanks for suggesting another option Thomas.Thomas, is there is any way so that I can make particular rows read only . If suppose I want to make those rows read only whose IsRequired property is false in MyClass
Ashish Ashu
There is a way to do this, by handling the CellBeginEdit event. In the handler, you check whether the row can be edited, and cancel the event (e.Cancel = true) if it can't
Thomas Levesque
A: 

Or you can set the visible property of the column to false. For each set of business data I want to display, I keep track of the # of leftmost-columns I want hidden because they hold PK values. Here's a sample:

     dgvDisplaySet.DataSource = _setSource
 gridColsToHide = _displaySet.hidePKFields
 For gridCol = 0 To dgvDisplaySet.Columns.Count - 1
  dgvDisplaySet.Columns(gridCol).Visible = (gridCol >= gridColsToHide)
 Next
Beth