PropertyGrid control in VB.NET
In this article we demonstrate on what is PropertyGrid control,it's property and how to use it.
A visual basic PropertyGrid control displays properties for any object or type and it retrieves the item's properties, primarily using reflection. It provides access to the properties it represents but not in a very friendly way. It holds them in a tree structure. The exact structure depends on whether the user is displaying Items by category or alphabetically.
Properties of PropertyGrid control
- AccessibleRole:- Determines the accessible role of the control.
- ActiveControl:- Determines the Active control on the Container control.
- AllowDrop:- Shows a value indicating whether the control can accept data that the user drags onto it.
- AutoScaleMode:- Determines the automatic Scaling mode of the control.
- BackColor:- Gets or sets the background color of the control
How to use PropertyGrid control
- Open a new project.
- Drag a PropertyGrid control on form. The form will look like below.
-
Write the below code.
Imports System.ComponentModel
<DefaultPropertyAttribute("Title")> _
Public Class SimpleProperties
Private _Title As String
Private _Show As Boolean
Private _Number As Short
<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Enter Title for the application")> _
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal Value As String)
_Title = Value
End Set
End Property
<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute("True"), _
DesignOnly(False), _
DescriptionAttribute("Show option")> _
Public Property Show() As Boolean
Get
Return _Show
End Get
Set(ByVal Value As Boolean)
_Show = Value
End Set
End Property
<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute("0"), _
DesignOnly(False), _
DescriptionAttribute("Enter a number")> _
Public Property Number() As Short
Get
Return _Number
End Get
Set(ByVal Value As Short)
_Number = Value
End Set
End Property
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PropertyGrid1.SelectedObject = New SimpleProperties()
End Sub
Output