0
votes

I have a form that contains a few DataGridViews. In the Form's Load event, I create DataTables and bind the DataGridView DataSources to those tables, like so (for example):

    newObject.Environment = New DataSet
    tblTemps = New DataTable("Temp")
    tblTemps.Columns.Add("Date", GetType(Date))
    tblTemps.Columns.Add("Temp (F)", GetType(Single))
    newObject.Environment.Tables.Add(tblTemps)
    dgvTemp.DataSource = newObject.Environment.Tables("Temp")

In design, the DataGridViews have AllowUserToAddRows and AllowUserToDeleteRows set to True. So what I would expect is that when this form loads, dgvTemp will show a grid with the 2 columns and 1 empty 'New' row.

But this is not what is happening - the grids are completely empty. Any ideas why? Any help is greatly appreciated!

Note I set the data source to the tables in that fashion because I want the user to be able to enter data in the grids and have the data tables be updated accordingly.

1
Set a breakpoint on the first line and ensure that whatever newObject is, it is initialized (isnt Nothing). If you encounter an NRE in form load, VS can often swallow the exception. - Ňɏssa Pøngjǣrdenlarp
If after steps advised by @Plutonix, DataGridView will be still empty, then check that DataGridView.AutoGenerateColumns = true - Fabio

1 Answers

0
votes

I took both Plutonix's and Fabio's suggestions - it's true, I was not initializing newObject before that block, and I added the .AutoGenerateColumns = True just to be sure. Now it works! Thank you very much!