473,811 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Object data binding, polymorphism and inheritance

1 New Member
I'm hoping that someone out there can give me some guidance here, and I hope that I am explaining this properly.


Here is my scenerio:

I have a BaseData object that serves as an abstract object for all my business objects. Notice there is an overridable method on the object.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class BaseData
  3.  
  4.         Dim msDataID As String
  5.         Dim msDescription As String
  6.  
  7.  
  8.  
  9.         <DataMember()>
  10.         Property DataID() As String
  11.             Get
  12.                 DataID = msDataID
  13.             End Get
  14.             Set(ByVal value As String)
  15.                 msDataID = value
  16.             End Set
  17.         End Property
  18.  
  19.         Property Description() As String
  20.             Get
  21.                 Description = msDescription
  22.             End Get
  23.             Set(ByVal value As String)
  24.                 msDescription = value
  25.             End Set
  26.         End Property
  27.  
  28.             Public Overridable Function GetAllObjects() As BaseDataCollection
  29.  
  30.                     Dim colObjects As BaseDataCollection = Nothing
  31.  
  32.                     colObjects = (get data from data source)
  33.  
  34.                     Return colObjects
  35.             End Function
  36.  
  37.  
  38.  
  39. End Class
  40.  

Here is the base Collection that servers as the abstract collection for all my business object collections:

Expand|Select|Wrap|Line Numbers
  1. Public Class BaseDataCollection
  2.         Inherits BindingList(Of BaseData)
  3.         Implements IComponent
  4.  
  5. #Region "IComponent Implementation"
  6.         Private m_Site As ISite = Nothing
  7.         Public Event Disposed(ByVal sender As Object, ByVal e As System.EventArgs) _
  8.             Implements System.ComponentModel.IComponent.Disposed
  9.  
  10.         Protected Property Site() As System.ComponentModel.ISite Implements _
  11.             System.ComponentModel.IComponent.Site
  12.             Get
  13.                 Return m_Site
  14.             End Get
  15.             Set(ByVal Value As System.ComponentModel.ISite)
  16.                 m_Site = Value
  17.             End Set
  18.         End Property
  19.  
  20.         Public Sub Dispose() Implements System.IDisposable.Dispose
  21.             Me.Items.Clear()
  22.             RaiseEvent Disposed(Me, System.EventArgs.Empty)
  23.         End Sub
  24. #End Region
  25.  
  26. #Region "IBindingList Sorting Features"
  27.         Private m_SupportsSorting As Boolean = True
  28.         Private m_SortProperty As PropertyDescriptor
  29.         Private m_SortDirection As ListSortDirection
  30.         Private m_OriginalList As ArrayList
  31.  
  32.         Protected Overrides ReadOnly Property SupportsSortingCore() As Boolean
  33.             Get
  34.                 Return m_SupportsSorting
  35.             End Get
  36.         End Property
  37.         Protected Overrides ReadOnly Property SortDirectionCore() As System.ComponentModel.ListSortDirection
  38.             Get
  39.                 Return m_SortDirection
  40.             End Get
  41.         End Property
  42.  
  43.         Protected Overrides ReadOnly Property SortPropertyCore() As System.ComponentModel.PropertyDescriptor
  44.             Get
  45.                 Return m_SortProperty
  46.             End Get
  47.         End Property
  48.  
  49.         Protected Overrides ReadOnly Property IsSortedCore() As Boolean
  50.             Get
  51.                 Return m_SortProperty Is Nothing
  52.             End Get
  53.         End Property
  54.  
  55.         Private Sub SaveList()
  56.             m_OriginalList = New ArrayList(Me.Items)
  57.         End Sub
  58.  
  59.         Private Sub ResetList(ByVal NewList As ArrayList)
  60.             Me.ClearItems()
  61.             For Each m_Student As BaseData In NewList
  62.                 Me.Add(m_Student)
  63.             Next
  64.         End Sub
  65.  
  66.         Private Sub DoSort()
  67.             Dim m_Comparer As New BaseDataComparer(m_SortProperty, m_SortDirection)
  68.             Dim m_SortList As New ArrayList(Me.Items)
  69.             m_SortList.Sort(m_Comparer)
  70.             ResetList(m_SortList)
  71.         End Sub
  72.  
  73.         Protected Overrides Sub ApplySortCore(ByVal prop As System.ComponentModel.PropertyDescriptor, ByVal direction As System.ComponentModel.ListSortDirection)
  74.             m_SortProperty = prop
  75.             m_SortDirection = direction
  76.             If (m_OriginalList Is Nothing) Then
  77.                 SaveList()
  78.             End If
  79.             DoSort()
  80.         End Sub
  81.  
  82.         Protected Overrides Sub RemoveSortCore()
  83.             ResetList(m_OriginalList)
  84.             m_SortDirection = Nothing
  85.             m_SortProperty = Nothing
  86.         End Sub
  87. #End Region
  88.  
  89.  
  90.  
  91.     End Class
  92.  
  93.  
Here is an example of a derived object that inherits BaseData:

Expand|Select|Wrap|Line Numbers
  1.  Public Class MyUser
  2.         Inherits BaseData
  3.  
  4.         Dim msUserName As String
  5.         Dim msPassword As String
  6.  
  7.  
  8.         Public Property UserName As String
  9.             Get
  10.                 Return msUserName
  11.             End Get
  12.             Set(ByVal value As String)
  13.                 msUserName = value
  14.             End Set
  15.         End Property
  16.  
  17.  
  18.         Public Property Password As String
  19.             Get
  20.                 Return msPassword
  21.             End Get
  22.             Set(ByVal value As String)
  23.                 msPassword = value
  24.             End Set
  25.         End Property
  26.  
  27.  
  28.  
  29.         Public Overrides Function GetAllObjects() As Collections.BaseDataCollection
  30.             Dim GetParams As New stcReadFileParams
  31.             Dim myProcessor As New MasterProcessor
  32.             Dim sObjectRec As String = ""
  33.             Dim colObject As Collections.MyUserCollection = Nothing
  34.  
  35.             GetParams.FileName = FileName
  36.             GetParams.KeyWord = RN_USERS
  37.             GetParams.Mode = MODE_INQUIRY
  38.  
  39.             If Not UVSession Is Nothing Then myProcessor.UVSession = UVSession
  40.  
  41.             sObjectRec = myProcessor.GetMaster(GetParams)
  42.  
  43.             If sObjectRec <> "" Then
  44.                 colObject = ParseRecordIntoObjects(sObjectRec)
  45.             End If
  46.  
  47.             Return colObject
  48.         End Function
  49.  
  50.  
  51.     End Class
  52.  

Here is an example of a derived collection:

Expand|Select|Wrap|Line Numbers
  1.     Public Class MyUserCollection
  2.         Inherits BaseDataCollection
  3.  
  4.     End Class
  5.  
When I try to databind the result from MyUser.GetAllOb jects to my gridView I am only seeing the BASEDATA object properties of DataID and Description. What am I doing wrong? I thought that the rules of polymorphism would strongly type the BindingList (of BaseData) in to BindingList (of MyUser) but that does not appear to be the case.

Any help would be greatly appreciated.
Jan 18 '11 #1
0 1128

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2353
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a visual representation of data. Two types of data binding are available for Windows Forms: Simple Data Binding and Complex Data Binding. Simple data binding allows you to bind one data element to a control. In many situations you want to display...
3
1983
by: Frank Wisniewski | last post by:
I have the following persudo code: //My Form Class class Form1 { //Local Variable for my custom object private MyCustomObject1 //Constructor for Form Class public Constructor{
3
41543
by: enchantingdb | last post by:
I have an exam tomorrow that covers the perceived advantages and disadvantages of object oriented programming, in particular polymorphism, inheritance and encapsulation. I know the advantages but am not clear on the disadvantages. I have had a look on the Web and in newsgroups but couldn't find much. As time is running out, I thought I would post here and hope that someone would reply. Thanks Rob
1
2605
by: matty.hall | last post by:
There's a lot of information out there about data-binding UI objects (i.e. derived from Control) to non-UI custom business objects. Is it possible to do the same without any UI being involved at all? Here's an example: I want to do data binding on some of the properties of a TreeNode (namely its Name). Unfortunately, TreeNode does not derive from Control, so it doesn't have the "stock" data binding stuff. I'd like to create a new...
2
1605
by: Davie | last post by:
Lets say i have an array of order objects and I wish for these objects to be bound to a ComboBox. public order(string id, string name, int price, string details) order orders = new ........... I know that i can bind them to a combobox by doing the following: comboBox1.DataSource=orders;
1
2728
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a collection object, and each collection element contains various pieces of information inside a custom object, including an id field.
19
2350
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
2
8994
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User object (custom class) is created, and properties are populated in each step of the wizard. In one of the steps, the User is assigned to 1 or more Programs. Assigned Programs are stored by the User object in a List, and displayed in a GridView in the...
8
11974
by: =?Utf-8?B?QXNo?= | last post by:
Hi, I have an object, for example User. User contains various properties which i have been able to bind to successfully using wizards and the form view. However if the class User has a property which is not a string, for example a custom type Address which contains properties such as StreetAddress, City, County, Country etc how do i bind to those properties on the same form view? I have tried doing Bind("Address.StreetAddress") but...
0
1052
by: hharry | last post by:
Hello All, I am binding a custom business object the gridview control. When I bind a datatable to the gridview control, the columns are displayed in the same order as the select statement used to populate the datatable. When I bind a custom business object to the gridview control, the column order is not the same as the order in which the business object
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.