Binding Collection to DataGrid without showing all columns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Orlando Cavadini

    Binding Collection to DataGrid without showing all columns

    Hello

    I bind a collection of objects with Type AB (Class AB) to a DataGrid control
    as following:

    Public Class AB
    Private m_AA As Integer
    Private m_AB As Integer
    Private m_AC As Integer

    Public Property AA() As Integer
    Get
    Return m_AA
    End Get
    Set(ByVal Value As Integer)
    m_AA = Value
    End Set
    End Property

    Public Property AB() As Integer
    Get
    Return m_AB
    End Get
    Set(ByVal Value As Integer)
    m_AB = Value
    End Set
    End Property

    Public Property AC() As Integer
    Get
    Return m_AC
    End Get
    Set(ByVal Value As Integer)
    m_AC = Value
    End Set
    End Property
    End Class
    ....

    Private m_list As New Collection
    ....

    Dim c As AB
    c = New AB
    c.AA = 9
    c.AB = 99
    c.AC = 999
    m_list.Add(c)
    c = New AB
    c.AA = 8
    c.AB = 88
    c.AC = 888
    m_list.Add(c)

    ....

    DataGridSection s.DataSource = m_list

    The DataGrid shows three columns AA, AB, AC with two rows of data. That
    works fine. But now, i'd like to show only the columns AB and AC. What do I
    have to do to get this result. Everything I tried failed.

    Many Thanks for your help in advance

    Orlando


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: Binding Collection to DataGrid without showing all columns

    Hi Orlando,

    Try to create a DataGridTableSt yle, set its MappingName to "AB" (or leave it
    empty - I really don't remember how to set MappingName properly when binding
    it to a collection). Then, create two instances of DataGridColumnS tyle and
    set their mapping names to "AA" and "AC" (or, maybe, "AB.AA" and "AB.AC").

    All these preparations should take place before calling the SetDataBinding
    method on the grid.

    P.S. The table styles and the column style can be created visually with the
    TableStyles collection designer and the GridColumnStyle s collection
    designer.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "Orlando Cavadini" <orlando.cavadi ni@sulzer.com> wrote in message
    news:3f7c40f9$0 $240$4d4ef98e@n ews.ch.uu.net.. .[color=blue]
    > Hello
    >
    > I bind a collection of objects with Type AB (Class AB) to a DataGrid[/color]
    control[color=blue]
    > as following:
    >
    > Public Class AB
    > Private m_AA As Integer
    > Private m_AB As Integer
    > Private m_AC As Integer
    >
    > Public Property AA() As Integer
    > Get
    > Return m_AA
    > End Get
    > Set(ByVal Value As Integer)
    > m_AA = Value
    > End Set
    > End Property
    >
    > Public Property AB() As Integer
    > Get
    > Return m_AB
    > End Get
    > Set(ByVal Value As Integer)
    > m_AB = Value
    > End Set
    > End Property
    >
    > Public Property AC() As Integer
    > Get
    > Return m_AC
    > End Get
    > Set(ByVal Value As Integer)
    > m_AC = Value
    > End Set
    > End Property
    > End Class
    > ...
    >
    > Private m_list As New Collection
    > ...
    >
    > Dim c As AB
    > c = New AB
    > c.AA = 9
    > c.AB = 99
    > c.AC = 999
    > m_list.Add(c)
    > c = New AB
    > c.AA = 8
    > c.AB = 88
    > c.AC = 888
    > m_list.Add(c)
    >
    > ...
    >
    > DataGridSection s.DataSource = m_list
    >
    > The DataGrid shows three columns AA, AB, AC with two rows of data. That
    > works fine. But now, i'd like to show only the columns AB and AC. What do[/color]
    I[color=blue]
    > have to do to get this result. Everything I tried failed.
    >
    > Many Thanks for your help in advance
    >
    > Orlando
    >
    >[/color]

    Comment

    Working...