Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Data Grid From Manually Defined Data Set

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
Its easy to set a data grid on a windows application from an data source but I can't get a grid set from a dataset I've created in the program from a list of folders. The grid just stays grey and displays nothing. It must be simple to solve. What am I missing?

Code:
' --------------------------
' Create A String Of Folders
' --------------------------

Dim strFolders() As String
strFolders = System.IO.Directory.GetDirectories("C:/Test1/")

' ------------------------------------------------------
' Create Internal DataSet And Populate With Folder Names
' ------------------------------------------------------

Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim idColumn As DataColumn
Dim nameColumn As DataColumn
Dim i As Integer

dt = New DataTable()
idColumn = New DataColumn("ID", Type.GetType("System.Int32"))
nameColumn = New DataColumn("FolderName", Type.GetType("System.String"))

dt.Columns.Add(idColumn)
dt.Columns.Add(nameColumn)

i = 0
Dim strMyString As String
For Each strMyString In strFolders


    dr = dt.NewRow()
    dr("ID") = i
    dr("FolderName") = strFolders(i).ToString
    dt.Rows.Add(dr)

    i = i + 1
Next


ds.Tables.Add(dt)


' -------------------------
' Display Folders In A Grid
' --------------------------

DataGridView1.DataSource() = ds.DefaultViewManager

Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
I hadn't specified the table.
I'd just specified the dataset.
The following line fixed my problem.

DataGridView1.DataSource = ds.Tables(0)

Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Just a thought and as a test. try adding the column names in the design view.
I used this code right now and it works.
Code:
        Dim Path As String
        Path = "c:\"

        Dim strFileSize As String = ""
        Dim di As New IO.DirectoryInfo(Path)
        Dim aryFi As IO.FileInfo() = di.GetFiles("*.pdf")
        Dim fi As IO.FileInfo
        Dim i As Integer
        Dim arrayFileList(300)
        Dim arrayFileCreatedDate(300)

        i = 0
        For Each fi In aryFi
            'FileDate = fi.CreationTime.ToString
            DataGridView1.Rows.Add(fi.Name, fi.CreationTime.ToString())

        Next

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top