Solved

Web Custom Control - Multi-level Properties

Posted on 2004-08-16
11
262 Views
Last Modified: 2010-04-07
I am creating a Web Custom Control based on a calendar dll I wrote.

The DLL has a class called CellProperties which had properties such as backcolor, forecolor, etc.  Then when I instantialed the dll I would set properties such as:

objCalendar.Heading.BackColor = Color.AliceBlue
objCalendar.Heading,ForeColor = Color.Black
etc...

Now, in creating this as a Web Custom Control, I want the properties to appear similar to the way Font shows up in the Propoerties screen.  That is, a title of Font with a "plus" box.  Then clicking on the "plus" will drop down the sub properties.

How do I do this?

I tried the following, but it doesn't work:

    <Bindable(True), Category("Appearence"), DefaultValue("")> Property [Heading]() As myCalendar.CellProperties
        Get
            Return m_propHeading
        End Get
        Set(ByVal Value As BCP.Web.Calendar.CellProperties)
            m_propHeading = Value
        End Set
    End Property
0
Comment
Question by:Clif
  • 4
  • 4
  • 3
11 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11812081
Have a look on the following article:

http://www.theserverside.net/developmentor/downloads/whitepapers/designint.pdf

HTH, nauman
0
 
LVL 10

Author Comment

by:Clif
ID: 11812672
Being the lazy person I am...

Is there any example in Visual Basic?
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 11812959
First, you need to make your custom property Public.  E.g.:

<Bindable(True), Category("Appearence"), DefaultValue("")> Public Property [Heading]() As myCalendar.CellProperties

All of the properties in myCalendar.CellProperties that you want to expose should also be Public.
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11812974
Actually, the .Net way is very easy either if you code in C# or VB. You just need to have concepts of Object Oriented programming, and since VB.net is an object oriented language, you will need to learn that too :) Its not that diffcult and I think you will be able to learn it quickly. While learning just glance on the way objects or statement defined in both the language.

Also have a look at the following URL cuz I think it has some good stuf:

http://www.microsoft.com/downloads/details.aspx?familyid=3ff9c915-30e5-430e-95b3-621dccd25150&displaylang=en

HTH, nauman
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 500 total points
ID: 11812999
Hey you know what, I found this tutorial that exactly do what you wanna do:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp

Best, Nauman
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Author Comment

by:Clif
ID: 11813531
The tutorial is also in C#.

I can code pretty darn well in VB.  I can also read a good bit of C (and C++ and C#).  But there are a few things I don't get.

For example, in the tutorial you posted:

   [TypeConverter(typeof(PersonConverter))]
   public class Person {
      private string firstName = "";
      private string lastName = "";
      private int    age = 0;
   
      public int Age {
         get {
            return age;
         }
         set {
            age = value;
         }
      }
     
      public string FirstName {
         get {
            return firstName;
         }
         set {
            this.firstName = value;
         }
      }

      public string LastName {
         get {
            return lastName;
         }
         set {
            this.lastName = value;
         }
      }      
   }

I can convert all of the above into VB except for the first line.

What the heck does this mean?
   [TypeConverter(typeof(PersonConverter))]


Also, again from the tutorial:
internal class PersonConverter : ExpandableObjectConverter {
     
   public override bool CanConvertFrom(
         ITypeDescriptorContext context, Type t) {

         if (t == typeof(string)) {
            return true;
         }
         return base.CanConvertFrom(context, t);
   }
.
.
.
}

Is this the same as (in VB)
Private Class PersonConverter
    Inherits ExpandableObjectConverter
    Public Overrides Function CanConvertFrom(context As ITypeDescriptorContext, t As Type)
        If TypeOf(t) Is String Then
            Return True
        End If
        'In the next line, what is the VB equivelant of 'base'?
        Return base.CanConvertFrom(context, t)
   End Function
.
.
.
End Class
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 11813756
> What the heck does this mean?
   [TypeConverter(typeof(PersonConverter))]

It is the C# version of Attributes:
   <TypeConverterAttribute(typeof(PersonConverter))> Public Class Person
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11814354
Private Class PersonConverter
    Inherits ExpandableObjectConverter
    Friend Overrides Function CanConvertFrom(context As ITypeDescriptorContext, t As Type)
        If TypeOf(t) Is String Then
            Return True
        End If
        'In the next line, what is the VB equivelant of 'base'?
        Return base.CanConvertFrom(context, t)
   End Function
.
.
.
End Class
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 11814854
base -> mybase
0
 
LVL 10

Author Comment

by:Clif
ID: 11820062
Ok, using the code from the link provided by nauman_ahmed at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp
I rewrote it from C# to VB.net.

It isn't working.  Where did I go wrong?

'Step 1:
'Tried:
'       <TypeConverterAttribute(typeof(PersonConverter))> Public Class Person
' as JustinW suggested, error "Is Expected")
<TypeConverter("PersonConverter")> Public Class Person
    Private m_sFirstName As String = ""
    Private m_sLastName As String = ""
    Private m_nAge As Integer = 0

    Public Property Age() As Integer
        Get
            Return m_nAge
        End Get
        Set(ByVal Value As Integer)
            m_nAge = Value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return m_sFirstName
        End Get
        Set(ByVal Value As String)
            m_sFirstName = Value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return m_sLastName
        End Get
        Set(ByVal Value As String)
            m_sLastName = Value
        End Set
    End Property

'Step 2:
    Private Class PersonConverter
        Inherits ExpandableObjectConverter

        Public Overloads Function CanConvertFrom(ByVal context As ITypeDescriptorContext, _
                                                 ByVal t As Type) As Boolean

            If TypeOf (t) Is String Then
                Return True
            End If
            Return MyBase.CanConvertFrom(context, t)
        End Function

'Changed from Overrides to Overloads because VB.net didn't like the former
        Public Overloads Function ConvertFrom(ByVal context As ITypeDescriptorContext, _
                                              ByVal info As System.Globalization.CultureInfo, _
                                              ByVal value As Object) As Object

            Try
                If TypeOf (value) Is String Then
                    Dim s As String = CType(value, String)
                    ' parse the format "Last, First (Age)"
                    '
                    Dim comma As Integer = s.IndexOf(",")
                    If comma <> -1 Then
                        ' now that we have the comma, get
                        ' the last name.
                        Dim last As String = s.Substring(0, comma)
                        Dim paren As Integer = s.LastIndexOf("(")
                        If paren <> -1 And _
                              s.LastIndexOf(")") = s.Length - 1 Then
                            ' pick up the first name
                            Dim first As String = _
                                  s.Substring(comma + 1, paren - comma - 1)
                            ' get the age
                            Dim age As Integer = Int32.Parse(s.Substring(paren + 1, s.Length - paren - 2))
                            Dim p As Person = New Person
                            p.Age = age
                            p.LastName = last.Trim()
                            p.FirstName = first.Trim()
                            Return p
                        End If
                    End If
                End If
            Catch
                ' if we got this far, complain that we
                ' couldn't parse the string
                '
                Throw New ArgumentException("Can not convert '" + CType(value, String) + "' to type Person")

            End Try
            Return MyBase.ConvertFrom(context, info, value)
        End Function

'Changed from Overrides to Overloads because VB.net didn't like the former
        Public Overloads Function ConvertTo(ByVal context As ITypeDescriptorContext, _
                                            ByVal culture As System.Globalization.CultureInfo, _
                                            ByVal value As Object, _
                                            ByVal destType As Type) As Object
            If TypeOf (destType) Is String And TypeOf (value) Is Person Then
                Dim p As Person = CType(value, Person)
                ' simply build the string as "Last, First (Age)"
                Return p.LastName & ", " & p.FirstName & " (" & p.Age.ToString() & ")"
            End If
            Return MyBase.ConvertTo(context, culture, value, destType)
        End Function
    End Class
End Class

'Step 3 (Goes in Web Custom Control class):
    Private p As Person = New Person
    Public Property [Person]() As Person
        Get
            Return p
        End Get
        Set(ByVal Value As Person)
            p = Value
        End Set
    End Property
0
 
LVL 10

Author Comment

by:Clif
ID: 11823131
Ok, I found a great C# to VB Translator here:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

The code produced from the demo provided works (almost).  The properties show up on the properties list as I wanted.

Actually I wasn't too far off in the translation I did.  :)


At any rate, as I said it *almost* works.  Everything is fine except the Web Custom Control doesn't respond to the properties.

Be on the look out for another question from me on this matter.  :)

Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now