2003-07-15

Getting the Most Out of the .NET Framework PropertyGrid Control

Getting the Most Out of the .NET Framework PropertyGrid Control

I started tinkering with the PropertyGrid control today. It sure makes it easy to build advanced edit UI's quickly. It has provisions for creating custom drop down boxes and such.

I got a little stuck when I introduced the DataSet object to the PropertyGrid Control. It displays *ALL* of the rows' public properties:



To mask the unwanted properties I created a DataRow facade:


public class HouseFacade
{
private HouseDataset.HouseRow _currentRow;

public void SetCurrentRow(HouseDataset.HouseRow row)
{
_currentRow = row;
}

[CategoryAttribute("Address"),
ReadOnlyAttribute(false),
Description("The street address")]
public string Address
{
get { return (_currentRow["Address"] as string ); }
set { _currentRow["Address"] = value; }
}

[CategoryAttribute("Address"),
ReadOnlyAttribute(false),
Description("name of the city")]
public string City
{
get { return(_currentRow["City"]); }
set { _currentRow["City"] = value; }
}


This gives me a bit more control, because now I can set the PropertyGrid related attributes (CategoryAttribute, Description, etc).



(The HouseFacade class is a great case for code generation.)

0 Comments:

Post a Comment

<< Home