(華版)
過去如果要冩一個簡單的PropetyGrid控制項(圖一)可以説是难以登天(復雜的很)。。。但是現在.NET就可以用四個字來形容。。。非常容易!

你只需加入.NET内建的PropertyGrid控制項,然後在冩一個很簡單的EmployeeProp Class就可以了。但是此Class就有一點點特别。。。那就是在Class的聲明前加上此tag。
<DefaultPropertyAttribute("Title"), DescriptionAttribute("")>
然後于每一項Property都要加上以下的tag。
<CategoryAttribute(""), _
Browsable(True|False), _
[ReadOnly](True|False), _
BindableAttribute(True|False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("")>
當编冩好了EmployeeProp Class,下一步就是把PropertyGrid1.SelectedObject的值數設為剛聲明並實例EmployeeProp Class的對象變量就完成了。
點撃下載程序代碼。
Form1的源代碼:
EmployeeProp Class的源代碼:
Imports System.ComponentModel

<DefaultPropertyAttribute("Title"), _
DescriptionAttribute("員工資料")> _
EmployeeProp
Private _FirstName As String
Private _LastName As String
Private _Age As String
Private _Gentle As String
Private _DateHire As Date
Private _Position As String
Private _Department As String
Private _Salary As String

<CategoryAttribute("員工個人資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工的名字。")> _
![]()
Get
Return _FirstName
End Get
Set(ByVal Value As String)
_FirstName = Value
End Set
End Property

<CategoryAttribute("員工個人資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工的姓氏。")> _
![]()
Get
Return _LastName
End Get
Set(ByVal Value As String)
_LastName = Value
End Set
End Property

<CategoryAttribute("員工個人資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工的年龄。")> _
![]()
Get
Return _Age
End Get
Set(ByVal Value As String)
_Age = Value
End Set
End Property

<CategoryAttribute("員工個人資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工的性别。")> _
![]()
Get
Return _Gentle
End Get
Set(ByVal Value As String)
_Gentle = Value
End Set
End Property

<CategoryAttribute("人事部資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工聘請日期。")> _
![]()
Get
Return _DateHire
End Get
Set(ByVal Value As Date)
_DateHire = Value
End Set
End Property

<CategoryAttribute("人事部資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工的执行職位。")> _
![]()
Get
Return _Position
End Get
Set(ByVal Value As String)
_Position = Value
End Set
End Property

<CategoryAttribute("人事部資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工所服務的部門。")> _
![]()
Get
Return _Department
End Get
Set(ByVal Value As String)
_Department = Value
End Set
End Property

<CategoryAttribute("人事部資料"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("員工所领取的薪金。")> _
![]()
Get
Return _Salary
End Get
Set(ByVal Value As String)
_Salary = Value
End Set
End Property

End Class