Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Web Custom Control - Multi-level Properties

Posted on 2004-08-16
11
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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