Andy
Andy

Reputation: 646

DataGridViews not showing on form

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.

Upvotes: 0

Views: 106

Answers (1)

Andy
Andy

Reputation: 646

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!

Upvotes: 0

Related Questions