?
Solved

Preventing DataGrid from showing child "tables" when bound to an arraylist of a class that also has an arraylist exposed as a property

Posted on 2006-05-08
4
Medium Priority
?
196 Views
Last Modified: 2010-04-23
I'm binding a datagrid to a class that exposes a number of properties including an ArrayList that is populated with objects instantiating  "children" of the main class.

This seems to produce 2 "tables" for the datagrid which then displays the "+" to allow you to see the children.  cool, but ugly, and i don't want to display the children here.

How can I prevent this?  and how do i set a TableStyle.MappingName (or whatever) so that the datagrid will use it?  

please see example below..., 3 files
      Public Class Dish, Public Class Eatery, Public Class Form1
thanks

''''''''''''''''''''''''''
''''' Public Class Dish
''''''''''''''''''''''''''
Public Class Dish
    Private _Name As String
    Private _Rating As Integer

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal Value As String)
            _Name = Value
        End Set
    End Property
    Public Property Rating() As Integer
        Get
            Return _Rating
        End Get
        Set(ByVal Value As Integer)
            _Rating = Value
        End Set
    End Property
    Public Sub New(ByVal Name As String, ByVal Rating As Integer)
        _Name = Name
        _Rating = Rating
    End Sub
End Class

''''''''''''''''''''''''''
''''' Public Class Eatery
''''''''''''''''''''''''''
Public Class Eatery
    Private _Name As String
    Private _Address As String
    Private _Dishes As New ArrayList

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal Value As String)
            _Name = Value
        End Set
    End Property

    Public Property Address() As String
        Get
            Return _Address
        End Get
        Set(ByVal Value As String)
            _Address = Value
        End Set
    End Property

    Public Property Dishes() As ArrayList
        Get
            Return _Dishes
        End Get
        Set(ByVal Value As ArrayList)
            _Dishes = Value
        End Set
    End Property

    Public Sub New(ByVal Name As String, ByVal Address As String)
        _Name = Name
        _Address = Address
    End Sub
End Class

''''''''''''''''''''''''''
''''' Public Class Form1
''''''''''''''''''''''''''
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim objEateries As New ArrayList
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call
    End Sub
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub

InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        CType(Me.DataGrid1,

System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor =

System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(16, 16)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(416, 224)
        Me.DataGrid1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(472, 358)
        Me.Controls.Add(Me.DataGrid1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.DataGrid1,

System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As

System.EventArgs) Handles MyBase.Load
        Dim objEatery As Eatery, i As Integer

        i = objEateries.Add(New Eatery("Taco d'Town", "101 Burrito

Avenue"))
        objEatery = CType(objEateries(i), Eatery)
        With objEatery
            .Dishes.Add(New Dish("Chili Rejeno", 5))
            .Dishes.Add(New Dish("Sopa Ropa", 1))
            .Dishes.Add(New Dish("Sopapilla", 15))
        End With

        i = objEateries.Add(New Eatery("Garage Mahal", "303 Janpath"))
        objEatery = CType(objEateries(i), Eatery)
        With objEatery
            .Dishes.Add(New Dish("Delhi Belly", 7))
            .Dishes.Add(New Dish("Some Mo, Suh", 15))
            .Dishes.Add(New Dish("Unglee Chaat", 1))
        End With

        objEateries.Add(New Eatery("Thai One On", "545 Slosh Street"))
        objEateries.Add(New Eatery("Grease Is Us", "9834 Lard Boulevard"))

        DataGrid1.DataSource = objEateries

    End Sub
End Class



0
Comment
Question by:digibaba
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 16635921
1) .NET version?

2) If believe it is DataGrid.AllowNavigation = False

Bob
0
 

Author Comment

by:digibaba
ID: 16636429
Thanks Bob O LearnedOne

1) Microsoft Visual Basic .NET= 69462-335-0000007-18325  and  .NET Framework = 1.1.4322 SP1
2) Yup!  that works wonders... great, thank you..

How about the second part of the question.. i.e.  How do I tell the datagrid to use a TableStyle.    I tried to set the MappingName to the name of the property, please see snippet of code below..

        Dim TS As New DataGridTableStyle
        Dim COL As New DataGridTextBoxColumn
        TS.MappingName = "objEateries"   '<------------
        TS.DataGrid = DataGrid1               '<------------

        COL.MappingName = "Name"
        COL.HeaderText = "NOM"
        COL.Width = 50
        TS.GridColumnStyles.Add(COL)

        COL = New DataGridTextBoxColumn
        COL.MappingName = "Address"
        COL.HeaderText = "Dressy"
        COL.Width = 100
        TS.GridColumnStyles.Add(COL)

        DataGrid1.DataSource = objEateries
        DataGrid1.AllowNavigation = False
        DataGrid1.TableStyles.Add(TS)   '<------------

 
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 1000 total points
ID: 16636704
Change the line
         TS.MappingName = "objEateries"  
To
         TS.MappingName = "ArrayList"  
0
 

Author Comment

by:digibaba
ID: 16636805
Hey alright arif....

i suppose i'll split the points 50/50.

never done this before... hope it works and thangs to both of you

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question