Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,

I'm new here!!!

I just want to ask if is it possible to add a property within a property at VB.Net.

Sample
 
Public Class Form1
 
        Private xproperties As PreferenceProperties
 
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            xproperties = New PreferenceProperties
 
            PropertyGrid1.SelectedObject = xproperties
        End Sub
 
    End Class
 
Public Class PreferenceProperties
 
    Private DBDetails As DatabaseProperties
 
    Public Sub New()
        DBDetails = New DatabaseProperties
    End Sub
 
    <Category("Connection")> _
    <Description("")> _
    <DisplayName("Database Properties")> _
    Public Property Database() As DatabaseProperties
        Get
            Return DBDetails
        End Get
        Set(ByVal value As DatabaseProperties)
            DBDetails = value
        End Set
    End Property
 

End Class
 
Public Class DatabaseProperties
    Private DBHost As String
    Private DBPort As Integer
    Private DBUser As String
    Private DBName As String
    Private DBPass As String
 
    Public Sub New()
        Me.DBHost = String.Empty
        Me.DBPort = 3306
        Me.DBUser = String.Empty
        Me.DBName = String.Empty
        Me.DBPass = String.Empty
    End Sub
 
    <Category("Connection")> _
    <Description("Host Name/IP address of the server where the database resides.")> _
    <DefaultValue(GetType(String), "")> _
    <DisplayName("Host Address")> _
    <Browsable(True)> _
    <ReadOnlyAttribute(False)> _
    Public Property HostName() As String
        Get
            Return Me.DBUser
        End Get
        Set(ByVal value As String)
            Me.DBUser = value
        End Set
    End Property
 

    <Category("Connection")> _
    <Description("The name of the database that you will be connected.")> _
    <DefaultValue(GetType(String), "")> _
    <DisplayName("Database Name")> _
    <Browsable(True)> _
    <ReadOnlyAttribute(False)> _
    Public Property DatabaseName() As String
        Get
            Return Me.DBName
        End Get
        Set(ByVal value As String)
            Me.DBName = value
        End Set
    End Property
 
    <Category("Connection")> _
    <Description("Port number that the database server is using. The default is 3306.")> _
    <DefaultValue(GetType(Integer), "3306")> _
    <DisplayName("Port Number")> _
    <Browsable(True)> _
    <ReadOnlyAttribute(False)> _
    Public Property PortNumber() As Integer
        Get
            Return Me.DBPort
        End Get
        Set(ByVal value As Integer)
            Me.DBPort = value
        End Set
    End Property
 

 
    <Category("Security")> _
    <Description("User name to be use in connecting the server.")> _
    <DefaultValue(GetType(String), "")> _
    <DisplayName("UserName")> _
    <Browsable(True)> _
    <ReadOnlyAttribute(False)> _
    Public Property UserName() As String
        Get
            Return Me.DBUser
        End Get
        Set(ByVal value As String)
            Me.DBUser = value
        End Set
    End Property
 
    <Category("Security")> _
    <Description("Password to be use in connecting the server.")> _
    <DefaultValue(GetType(String), "")> _
    <DisplayName("Password")> _
    <Browsable(True)> _
    <PasswordPropertyText(True)> _
    <ReadOnlyAttribute(False)> _
    Public Property Password() As String
        Get
            Return Me.DBPass
        End Get
        Set(ByVal value As String)
            Me.DBPass = value
        End Set
    End Property
 
End Class
 
 
This works with when you are in source code, but once you set the property to propertygrid the property becomes readonly.
 

Can someone help me on this?

Thanks in advance...
Posted 11-Jan-13 16:26pm
SherMags1.3K
Edited 11-Jan-13 17:14pm
v4
Comments
PIEBALDconsult at 11-Jan-13 23:02pm
   
What does the compiler tell you? I don't really understand the question. The code seems fairly reasonable, but don't have much experience with VB.
SherMags at 12-Jan-13 0:25am
   
Hi PIEBALDconsult,
 
The code is good, but when i load it to propertygrid the "Database Properties" item was disabled and I can't view the properties of the database.
PIEBALDconsult at 12-Jan-13 0:34am
   
Then I wouldn't be any help. Good luck.
Sandeep Mewara at 11-Jan-13 23:13pm
   
Your sample code above does not say anything of property-in-property. All looks ok. Can you be clearer on what you seek?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This was already solved
 
www.daniweb.com[Add property to a property]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 450
2 Kornfeld Eliyahu Peter 305
3 Ravi Bhavnani 200
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 6,890
1 OriginalGriff 6,761
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100