473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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)

....

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
Nov 20 '05 #1
1 6163
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" <or**************@sulzer.com> wrote in message
news:3f*********************@news.ch.uu.net...
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


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: K | last post by:
I created a collection which is derived from ArrayList and implements IBindingList and ITypedList. Then I bound the DataSource of a data grid into the collection. It could show up the data but...
4
by: Matt | last post by:
Hi, I've been thinking about how to do this, but can't think of a solution. I have a class that is derived from System.Web.UI.WebControls.DataGrid which works a treat, but I'd like to extend...
2
by: John Sun | last post by:
Hi, Dear gurus, I want to bind my collection to a datagrid. The field names in my object show up in a weird order, and I just wonder how I could reorder those columns . I find some code like...
3
by: bbernieb | last post by:
Hi, All, Is it possible to access a variable inside of a data binding, without the variable being out of scope? (Note: On the DataBinder line, I get an error message that says "Name 'i' is...
1
by: Demetri | last post by:
Someone posted the following back in June and I am now doing the same thing. I'll just paste what was asked and see if anyone can give us an answer: ...
0
by: Leigh Webber | last post by:
I have an ActiveX dll written in VB6. It exposes a class called CustomerDisplays, with a Public Function NewEnum (procedure ID -4, hide this member), and a Public Function Item (default) and a...
1
by: viktor9990 | last post by:
I'm trying to bind a custom collection to an autogenerated datagrid without success. I'm getting this error: DataGrid with id 'DataGrid2' could not automatically generate any columns from the...
2
by: Merk | last post by:
I'm new to .NET (using 2.0) and was wondering how to go about binding a collection of custom classes to a DataGrid. The class exposes 5 read-only String properties. I would like for each of...
1
by: Suresh | last post by:
Using ASP.NET 1.1 ---------------------- I have a custom collection of object that I'm binding to a datagrid. Each of these objects have another collection inside them. I have a user control...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...

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.