PC Review


Reply
Thread Tools Rate Thread

Binding Collection to DataGrid without showing all columns

 
 
Orlando Cavadini
Guest
Posts: n/a
 
      2nd Oct 2003
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)

....

DataGridSections.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


 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      3rd Oct 2003
Hi Orlando,

Try to create a DataGridTableStyle, 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 DataGridColumnStyle 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 GridColumnStyles collection
designer.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Orlando Cavadini" <(E-Mail Removed)> wrote in message
news:3f7c40f9$0$240$(E-Mail Removed)...
> 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)
>
> ...
>
> DataGridSections.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
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid binding to collection with rowfiltering like dataview =?Utf-8?B?RHVhbmU=?= Microsoft Dot NET Framework 0 18th Mar 2006 01:57 AM
Binding collection to a asp.net DataGrid - order of columns display question David Laub Microsoft ASP .NET 0 3rd Aug 2004 09:23 PM
Datagrid: Binding to custom collection Carlos Campos Microsoft Dot NET Framework Forms 3 24th Jun 2004 05:09 PM
Binding a Datagrid to a Custom Collection Stephajn Craig Microsoft VB .NET 0 4th Feb 2004 06:54 PM
DataGrid Binding to Complex Custom Collection Conawapa11 Microsoft ASP .NET 1 14th Nov 2003 11:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:51 AM.