Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Component with DataTables. How to impliment?
 

Component with DataTables. How to impliment?

I'm creating a business object as a component that sits in the tray of a winform or ASP.Net page.

This component will have functions that fill data tables. I would like to expose these data tables to binding similar to how the DataSet works.

I presume from the documentation that you need to impliment IListSource.  I can get the base component to show up as a data source under a Datagrid when I impliment IListSource, but I can't get the DataMember property to list any of the DataTables.

What am I doing wrong? Am I even on the right track?

Thanks for any help you can provide!
MigrationUser 1  Tuesday, April 29, 2003 1:53 PM
Can you post your implementation of IList.GetList?
MigrationUser 1  Tuesday, April 29, 2003 2:26 PM
That's just the thing. I have no clue what this is supposed to be. The documentation is THIN to say the least.

I tried creating an array list that contained all of my data tables that I wanted available, but that didn't seem to work.

ArrayList al = new ArrayList();
al.Add(pdsTest);
...

return al;

I got a blank drop down for data member, although data source had the component listed.
MigrationUser 1  Tuesday, April 29, 2003 11:57 PM
Your best bet will be to return a strongly typed collection from GetList and then it should work just fine.  An example of a strongly typed collection would be something like this:


Public Class MyObjectCollection
    Inherits CollectionBase

    Public Sub New()
        MyBase.New()
    End Sub

    Default Public Property Item(ByVal index As Integer) As MyObject
        Get
            Return CType(Me.List.Item(index), MyObject)
        End Get
        Set(ByVal Value As MyObject)
            Me.List.Item(index) = Value
        End Set
    End Property

    Public Function Add(ByVal MyObject As MyObject) As Integer
        Return Me.List.Add(MyObject)
    End Function

    Public Function Contains(ByVal MyObject As MyObject) As Boolean
        Return Me.List.Contains(MyObject)
    End Function

    Public Function IndexOf(ByVal MyObject As MyObject) As Integer
        Return Me.List.IndexOf(MyObject)
    End Function

    Public Sub Insert(ByVal Index As Integer, ByVal MyObject As MyObject)
        Me.List.Insert(Index, MyObject)
    End Sub

    Public Sub Remove(ByVal MyObject As MyObject)
        Me.List.Remove(MyObject)
    End Sub
End Class


I created a rudimentary test app using a strongly typed collection and it worked just fine...  

Let me know if you have any questions..
MigrationUser 1  Wednesday, April 30, 2003 10:17 AM
Ok, so I created that strongly typed collection.  Instead of MyObject I used DataTable.

The problem is that it now it appears to be binding the data grid to the first column's information.

(i.e. dataType etc.)

What am I missing?
MigrationUser 1  Wednesday, April 30, 2003 2:20 PM
Well, I just stumbled on something that isn't much going to make your day with this... Apparently, IListSource is, in some manner, fundamentally broken.  There are work arounds, but they aren't too pretty.  I recommend reading this <a href="http://noiseehc.freeweb.hu/IListSource.html">article</a> as it provides pretty good insight into this problem and how to workaround the problems.
MigrationUser 1  Wednesday, April 30, 2003 4:51 PM
Thanks for the info.... didn't come up in google when I did a search....

MS should be reading articles like this and fixing them as quickly as possible so that this type of thing goes away quickly. It's hacks like this that make .net look bad...
MigrationUser 1  Wednesday, April 30, 2003 5:19 PM

You can use google to search for other answers

Custom Search

More Threads

• DefaultValue attribute on a double property behaves inconsistently with Visual Studio property grid.
• Accessing list of all controls for a form at design time
• Control Overlap (weird!)
• Transparency Issue
• Potential Bug: Form Scroll Bar + Build
• Yikes: usercontrol inherits from abstract class
• Protected Members and Designer
• An error occurred while parsing EntityName
• How do I add scrolling to a derived Panel?
• Any help with Speech Recognition would be awesome!