LostProgrammer
Centurion
- Joined
- Jan 17, 2003
- Messages
- 123
I am trying to setup a datagrid but I keep getting this error:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
Here is my code:
The error here : dGridOneDay.TableStyles.Add(dGridTableStyle)
Dim adaptOneDay As New SqlClient.SqlDataAdapter("Select logtime, username from timelog", conSql)
Dim dsOneDay As DataSet
Dim dGridTableStyle As DataGridTableStyle
Dim dGridColumnTime As DataGridTextBoxColumn
Dim dGridColumnUser As DataGridTextBoxColumn
dGridOneDay.DataMember = "TimeLog"
dGridOneDay.DataSource = dsOneDay
dGridOneDay.HeaderForeColor = System.Drawing.SystemColors.ControlText
dGridOneDay.Location = New System.Drawing.Point(8, 152)
dGridOneDay.Name = "dGrid"
dGridOneDay.Size = New System.Drawing.Size(272, 208)
dGridOneDay.TabIndex = 2
dGridOneDay.TableStyles.Add(dGridTableStyle)
'dGridOneDay.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {dGridTableStyle})
dGridOneDay.Visible = False
dGridTableStyle.DataGrid = dGridOneDay
dGridTableStyle.GridColumnStyles.Add(dGridColumnTime)
dGridTableStyle.GridColumnStyles.Add(dGridColumnUser)
' dGridTableStyle.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {dGridColumnTime, dGridColumnUser})
dGridTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText
dGridTableStyle.MappingName = "TimeLog"
dGridColumnTime.Format = "MM/dd/yyyy hh:mm tt"
dGridColumnTime.FormatInfo = Nothing
dGridColumnTime.HeaderText = "Log Time"
dGridColumnTime.MappingName = "logTime"
dGridColumnTime.Width = 150
dGridColumnUser.Format = ""
dGridColumnUser.FormatInfo = Nothing
dGridColumnUser.HeaderText = "Username"
dGridColumnUser.MappingName = "username"
dGridColumnUser.Width = 75
adaptOneDay.Fill(dsOneDay, "Timelog")
For the life of me I do not know why....
Thanks
Lp
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
Here is my code:
The error here : dGridOneDay.TableStyles.Add(dGridTableStyle)
Dim adaptOneDay As New SqlClient.SqlDataAdapter("Select logtime, username from timelog", conSql)
Dim dsOneDay As DataSet
Dim dGridTableStyle As DataGridTableStyle
Dim dGridColumnTime As DataGridTextBoxColumn
Dim dGridColumnUser As DataGridTextBoxColumn
dGridOneDay.DataMember = "TimeLog"
dGridOneDay.DataSource = dsOneDay
dGridOneDay.HeaderForeColor = System.Drawing.SystemColors.ControlText
dGridOneDay.Location = New System.Drawing.Point(8, 152)
dGridOneDay.Name = "dGrid"
dGridOneDay.Size = New System.Drawing.Size(272, 208)
dGridOneDay.TabIndex = 2
dGridOneDay.TableStyles.Add(dGridTableStyle)
'dGridOneDay.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {dGridTableStyle})
dGridOneDay.Visible = False
dGridTableStyle.DataGrid = dGridOneDay
dGridTableStyle.GridColumnStyles.Add(dGridColumnTime)
dGridTableStyle.GridColumnStyles.Add(dGridColumnUser)
' dGridTableStyle.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {dGridColumnTime, dGridColumnUser})
dGridTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText
dGridTableStyle.MappingName = "TimeLog"
dGridColumnTime.Format = "MM/dd/yyyy hh:mm tt"
dGridColumnTime.FormatInfo = Nothing
dGridColumnTime.HeaderText = "Log Time"
dGridColumnTime.MappingName = "logTime"
dGridColumnTime.Width = 150
dGridColumnUser.Format = ""
dGridColumnUser.FormatInfo = Nothing
dGridColumnUser.HeaderText = "Username"
dGridColumnUser.MappingName = "username"
dGridColumnUser.Width = 75
adaptOneDay.Fill(dsOneDay, "Timelog")
For the life of me I do not know why....
Thanks
Lp