Solved

Web Custom Control - Multi-level Properties

Posted on 2004-08-16
11
255 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
Comment Utility
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
Comment Utility
Being the lazy person I am...

Is there any example in Visual Basic?
0
 
LVL 24

Expert Comment

by:Justin_W
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Author Comment

by:Clif
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
base -> mybase
0
 
LVL 10

Author Comment

by:Clif
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

12 Experts available now in Live!

Get 1:1 Help Now