VB Form Designer errors on custom control


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: VB Form Designer errors on custom control

  1. #1
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263

    Question VB Form Designer errors on custom control

    I have created a class that holds information about an event.
    The date the event triggers, if it is a repeating event, and the repeat interval.

    I have created a custom listbox control to display my events. It has a property for getting and setting a list of events to display. The property has the data type of: List(Of cEvent) where cEvent is my Event Class.

    When I add the control to a Form and then build the project, the form editor errors - and will no longer display or allow changes to the forms design.

    It seems to be that the designer is trying to set the value of the property, from within the forms designer.vb file. It does this by creating a resource in the forms resource file(.resx) and assigns it to the property. This is unsuccessful because it can't create a resource entry with a proper datatype. The datatype is set to null, which can't be converted to a valid type.

    Is there something I can do to keep VB from trying to assign a default value to this property. Or is there something I can do to my class or control to tell the form designer how to handle this?

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Interesting problem. I think this might be a bug, in the forms designer.
    When it tries to store a default value for the property in the forms resource file, and the data type is complex, like my List(Of cEvent). It ends up putting in a null value, which it cannot convert back to the correct data type.

    I solved this problem by modifying the custom control. I split the EventList property into two overloaded routines. An EventList Sub that takes the List(Of cEvent) as a paramater, and an EventList Function that Returns a List(Of cEvent).
    The EventList Sub takes the passed List(Of cEvent) and loads the listbox with the events.
    The EventList Function returns a List(Of cEvent) with the Items that are currently displayed by the listbox.

    The only change to the syntax was for Setting the EventList:

    MyListBox.EventList = myEvents
    ' became:
    MyListBox.EventList(myEvents)

    Retreiving the Items from the list box stayed the same:
    myEvents = MyListBox.EventList
    Last edited by Ron Weller; 05-17-2012 at 07:44 PM.

Similar Threads

  1. Windows form designer generated code VB
    By Benjamin in forum .NET
    Replies: 2
    Last Post: 04-05-2006, 04:06 AM
  2. Loading Custom Control onto the form
    By Sync in forum VB Classic
    Replies: 4
    Last Post: 12-07-2005, 02:21 AM
  3. Replies: 7
    Last Post: 10-28-2002, 01:10 PM
  4. They created J#, why couldn't they do VB#?
    By Thomas Eyde in forum .NET
    Replies: 290
    Last Post: 12-22-2001, 03:13 PM
  5. Passing a control array to a method
    By Willy Van den Driessche in forum VB Classic
    Replies: 6
    Last Post: 09-24-2001, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center