Solved

Problem populating DataGridView in VB.NET Forms App

Posted on 2009-07-14
2
516 Views
Last Modified: 2013-11-07
Hi,

I'm having trouble getting a DataGridView to populate in this simple VB.NET forms application.

I'm going through, creating the dataset, adding columns and then rows, but when I run the program, no exceptions are thrown, but my datagrid view is completely empty.

Can anyone suggest what might be wrong here?

Cheers
Imports ToDoListLibrary
Imports System.IO
Imports System.Data.SqlClient
 
 
Public Class ToDoListUI
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim toDoItem = New ToDoItem()
 
        toDoItem.ToDoItemDoneProperty() = False
        toDoItem.ToDoItemDoneDateTimeProperty() = DateTime.Now
        toDoItem.ToDoItemDoByDateTimeProperty() = DateTime.Now
        toDoItem.ToDoItemTextProperty() = ""
        toDoItem.ToDoItemPriorityProperty() = toDoItem.ToDoItemPriorityProperty().High
 
        Dim toDoList = New ToDoList()
 
        toDoList.ToDoItemListProperty().Add(toDoItem)
 
 
        Dim ds As DataSet = New DataSet()
 
        Dim tb As DataTable = ds.Tables.Add()
 
        tb.Columns.Add("ToDoItemDone", GetType(Boolean))
        tb.Columns.Add("ToDoItemDoneDateTime", GetType(DateTime))
        tb.Columns.Add("ToDoItemDoByDateTime", GetType(DateTime))
        tb.Columns.Add("ToDoItemText", GetType(String))
        tb.Columns.Add("ToDoItemPriority", GetType(ToDoItem.ToDoItemPriority))
 
 
        For Each toDo As ToDoItem In toDoList.ToDoItemListProperty()
 
            tb.Rows.Add(toDo.ToDoItemDoneProperty, toDo.ToDoItemDoneDateTimeProperty, _
                         toDo.ToDoItemDoByDateTimeProperty, toDo.ToDoItemTextProperty, _
                         toDo.ToDoItemPriorityProperty)
        Next
 
        m_toDoListUIDataGridView.DataSource = ds.DefaultViewManager
 
    End Sub
 
 
End Class

Open in new window

form.JPG
0
Comment
Question by:Cognize
2 Comments
 
LVL 1

Accepted Solution

by:
RSBuTCHeR earned 500 total points
ID: 24847770
Hi Cognize,

Try to use this line:

m_toDoListUIDataGridView.DataSource = ds.Tables(0)

or

m_toDoListUIDataGridView.DataSource = dt

Regards,

Falcko
0
 
LVL 2

Author Closing Comment

by:Cognize
ID: 31603175
Thanks mate, thats what I needed.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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