Extending DataGrid

Hello, I have followed microsoft's Walkthrough: Creating Your Own Collection Class to create my own Collection object.  I created the following classes:

Receipt, ReceiptItemCollection, ReceiptItem.

1. I have bound a datagrid to my ReceiptItemCollection.
2. I am having trouble customizing the appearance of the datagrid. (using this example) (basically nothing happens..datagrid is automatically creating columns)

I am supposed to specify a MappingName for the DataGridTableStyle and DataGridtextBoxColumn objects.  This mappingName property is of type String.  So i can't tell it to use the first column in the collection or the second...i must have column names apparently.

how do i know that i have names to map to in my custom Collection

---- SOURCE -----



Public Class ReceiptItemCollection
    Inherits System.Collections.CollectionBase

    Public ReadOnly Property Item(ByVal intIndex As Integer) As ReceiptItem
        Get
            Return CType(List.Item(intIndex), ReceiptItem)
        End Get
    End Property

    Public Sub Add(ByVal ri As ReceiptItem)
        List.Add(ri)
    End Sub

    Public Sub Remove(ByVal intIndex As Integer)
        If intIndex > Count - 1 Or intIndex < 0 Then
        Else
            List.RemoveAt(intIndex)
        End If
    End Sub

End Class

 





Public Class ReceiptItem

    Private decAmount As Decimal
    Public Property Amount() As Decimal
        Set(ByVal Value As Decimal)
            decAmount = Value
        End Set
        Get
            Return decAmount
        End Get
    End Property

    Private strDescription As String
    Public Property Description() As String
        Set(ByVal Value As String)
            strDescription = Value
        End Set
        Get
            Return strDescription
        End Get
    End Property

    Public Sub New(ByVal decAmount As Decimal, ByVal strDescription As String)
        Amount = decAmount
        Description = strDescription
    End Sub

End Class

 



Answer this question

Extending DataGrid

  • jfcma38

    1. Use the new Whidbey BindingList<T> list. It has the functionality needed to be used in DataBinding. In your case, you would created a BindingList<ReceiptItem>.

    2. See above.

    3. If you want to display data you should set DataGrid.DataSource to the instance of BindingList<ReceiptItem>. Also, please look into using the new Whidbey DataGridView control : it has a lot more features than the old DataGrid control.



  • KeFei Wang

    Thanks for the reply.  Where do i look into Whidbey   What IDE's can i use (do i have to throw out Visual Studio 200x)

    Thanks.

  • David Schulze

    You will need to install Whidbey.

    The generic BindingList<T> is defined in the System.ComponentModel namespace.

    The new DataGridView controls is defined in System.Windows.Forms namespace.

    Hope this helps.

    Daniel.

    This posting is provided "as-is".



  • rdrenker

    I've done some research and am attempting to be more specific in this post.

    Summary:  I have created a custom collection class.  I am trying to bind a datagrid with the data in the collection.  My problem is that i don't have any table names or column names to map the datagrid to for custom binding. 

    1.  Is my problem that i have not chosen the correct base class for the ReceiptItemCollection Class  

    2.  Would choosing a different class give me the interface i need

    3.  Should i be setting the DataGrid.DataSource to be my ReceiptItemCollection

    Thanks for any input.


  • Extending DataGrid