Solved

why doesn't the data table display (newbie)

Posted on 2004-09-03
3
221 Views
Last Modified: 2010-04-23
In the code below DS is the Dataset. WHy doesn't the following code display a table?

        Dim stTableName As String = "Search" & NewSearchID.ToString
        Dim DT As New DataTable()
        DT.TableName = stTableName

        DS.Tables.Add(DT)

        DT.Columns.Add("A1", Type.GetType("System.String"))
        DT.Columns.Add("A2", Type.GetType("System.String"))
        DT.Columns.Add("A3", Type.GetType("System.String"))
        DT.Columns.Add("A4", Type.GetType("System.String"))
        DT.Columns.Add("A5", Type.GetType("System.String"))
        DT.Columns.Add("A6", Type.GetType("System.String"))

        Dim iIndex As Long
        Dim DR As DataRow
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("A1") = Str$(iIndex)
            DR("A2") = Str$(iIndex)
            DR("A3") = Str$(iIndex)
            DR("A4") = Str$(iIndex)
            DR("A5") = Str$(iIndex)
            DR("A6") = Str$(iIndex)

            DT.Rows.Add(DR)
        Next

        NG.SetDataBinding(DS, stTableName)

    End Sub
0
Comment
Question by:rdavis101
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11978132
It does on my system.  Here is the testform I used:

Public Class Form1
    Inherits System.Windows.Forms.Form

#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 Button1 As System.Windows.Forms.Button
    Friend WithEvents NG As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.NG = New System.Windows.Forms.DataGrid
        CType(Me.NG, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(88, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'NG
        '
        Me.NG.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.NG.DataMember = ""
        Me.NG.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.NG.Location = New System.Drawing.Point(8, 40)
        Me.NG.Name = "NG"
        Me.NG.Size = New System.Drawing.Size(272, 216)
        Me.NG.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.NG)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.NG, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private DS As New DataSet
    Private NewSearchID As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim stTableName As String = "Search" & NewSearchID.ToString
        Dim DT As New DataTable
        DT.TableName = stTableName

        DS.Tables.Add(DT)

        DT.Columns.Add("A1", Type.GetType("System.String"))
        DT.Columns.Add("A2", Type.GetType("System.String"))
        DT.Columns.Add("A3", Type.GetType("System.String"))
        DT.Columns.Add("A4", Type.GetType("System.String"))
        DT.Columns.Add("A5", Type.GetType("System.String"))
        DT.Columns.Add("A6", Type.GetType("System.String"))

        Dim iIndex As Long
        Dim DR As DataRow
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("A1") = Str$(iIndex)
            DR("A2") = Str$(iIndex)
            DR("A3") = Str$(iIndex)
            DR("A4") = Str$(iIndex)
            DR("A5") = Str$(iIndex)
            DR("A6") = Str$(iIndex)

            DT.Rows.Add(DR)
        Next
        NG.SetDataBinding(DS, stTableName)
    End Sub

End Class
0
 

Author Comment

by:rdavis101
ID: 11978140
You're right, it does...thanks dude.

Roger
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11978147
Um...glad I could help.

=)
Idle_Mind
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now