Home › Forums › WinForms controls › Xceed Grid for WinForms › Master/Detail Grid gets error after building the detail grid using Relationship in SQL Express Database
-
AuthorPosts
-
#17529 |
I am building a master/detail grid that has worked in other applications (of course I have changed the tables/fields to work with current database).
After it builds the detail grid and I perform the Grid.EndInit() command, I get the error NullReferenceException was unhandled (Object reference not set to an instance of an object.
I know that this lies somewhere in how that relationship is referenced or used but can’t figure out where.
Here is my code that builds the grid:
Public Sub buildgrid()
Grid.Clear()
Grid.BeginInit() ‘ EndInit will be called later
Dim ColumnManagerRow1 As New ColumnManagerRow
Grid.SingleClickEdit = True
Grid.BackColor = Color.FromKnownColor(KnownColor.Control)
Grid.ScrollBars = GridScrollBars.None
‘SETUP=====================================================================================================
Grid.FixedHeaderRows.Add(ColumnManagerRow1)
‘ Add columns to the grid. In the case of our first column, the datatype will be button.
Grid.Columns.Add(New Column(“Edit”, GetType(System.Windows.Forms.Button)))
Grid.Columns.Add(New Column(“Delete”, GetType(System.Windows.Forms.Button)))
Grid.Columns.Add(New Column(“In”, GetType(System.Windows.Forms.TextBox)))
Grid.Columns.Add(New Column(“Out”, GetType(System.Windows.Forms.TextBox)))
Grid.Columns.Add(New Column(“Total Time”, GetType(System.Windows.Forms.TextBox)))
‘ Assign our custom row to the DataRowTemplate so that the grid will create our custom row rather than the default DataRow
Grid.DataRowTemplate = New CustomDataRow
‘ Set the current column
Grid.CurrentColumn = Grid.Columns(“Edit”)
Grid.DataSource = dSEmployees
Grid.DataMember = “Employees”
Dim columnname As New DataColumn
Dim columnnametext As String
‘ Add the grid to the form
Me.Controls.Add(Grid)
Grid.Dock = DockStyle.None
Grid.Left = 446
Grid.Top = 80
Grid.Width = Me.Width – 446
Grid.Height = Me.Height – 75 – Grid.Top
Grid.ScrollBars = GridScrollBars.Both
Grid.Columns(“Edit”).Width = 50
Grid.Columns(“Edit”).VisibleIndex = 0
Grid.Columns(“Delete”).VisibleIndex = 1
Dim MoneyFields As New Collection
MoneyFields.Add(Grid.Columns(“RegRate”))
MoneyFields.Add(Grid.Columns(“OTRate”))
Dim OmitFields As New Collection
OmitFields.Add(Grid.Columns(“EmployeeID”))
OmitFields.Add(Grid.Columns(“EmployeeNumber”))
OmitFields.Add(Grid.Columns(“PayTypeID”))
OmitFields.Add(Grid.Columns(“Supervisor”))
OmitFields.Add(Grid.Columns(“SearchKey”))
OmitFields.Add(Grid.Columns(“MiddleName”))
OmitFields.Add(Grid.Columns(“Birthdate”))
OmitFields.Add(Grid.Columns(“TermDate”))
OmitFields.Add(Grid.Columns(“CurrentStatus”))
OmitFields.Add(Grid.Columns(“TimeLineNum”))
OmitFields.Add(Grid.Columns(“Mgr”))
Dim omitcolumn As New Column
For Each omitcolumn In OmitFields
omitcolumn.Visible = False
Next
Grid.Columns(“Firstname”).Title = “First”
Grid.Columns(“LastName”).Title = “Last”
Grid.Columns(“DisplayName”).Title = “Display As”
Grid.Columns(“Addr1”).Title = “Address”
Grid.Columns(“Addr2”).Title = “Address 2”
Grid.Columns(“City”).Title = “City”
Grid.Columns(“State”).Title = “State”
Grid.Columns(“Zip”).Title = “Zip”
Grid.Columns(“HireDate”).Title = “Hire Date”
Grid.Columns(“LastReview”).Title = “Last Review Date”
Grid.Columns(“NextReview”).Title = “Next Review Date”
Grid.Columns(“RegRate”).Title = “Rate”
Grid.Columns(“OTRate”).Title = “OT Rate”
Grid.Columns(“PinNum”).Title = “Pin”
Grid.Columns(“HomeStoreID”).Title = “Home Store”
Grid.ScrollBars = GridScrollBars.Both
Dim numformat As New System.Globalization.NumberFormatInfo
Dim c As New Column
numformat.CurrencySymbol = “$”
numformat.CurrencyPositivePattern = 0
numformat.CurrencyNegativePattern = 1
For Each c In MoneyFields
c.FormatProvider = numformat
c.FormatSpecifier = “c”
Next
Dim col As Column
For Each col In Grid.Columns
If MoneyFields.Contains(“col.fieldname”) Then
col.HorizontalAlignment = Xceed.Grid.HorizontalAlignment.Center
col.VerticalAlignment = VerticalAlignment.Center
Else
col.HorizontalAlignment = Xceed.Grid.HorizontalAlignment.Center
col.VerticalAlignment = VerticalAlignment.Center
End If
Next
‘This is the child line which will contain the punches of each clock this relationship is created in SQL Server Express
Dim detail As New DetailGrid
detail.DataSource = Nothing
detail.DataMember = “FK_TimeclockPunches_Employees”
detail.HeaderRows.Add(New ColumnManagerRow)
detail.HeaderRows.Add(New InsertionRow)
detail.HeaderRows(1).BackColor = Color.LightYellow
detail.BackColor = Color.White
detail.Columns.Add(New Column(“EditLine”, GetType(System.Windows.Forms.Button)))
detail.Columns.Add(New Column(“DeleteLine”, GetType(System.Windows.Forms.Button)))
detail.Columns(“EditLine”).Width = 50
detail.Columns(“EditLine”).Title = “”
‘detail.Columns(“DeleteLine”).Title = “”
‘ detail.Columns(“DeleteLine”).Width = 60
detail.Columns(“id”).Visible = False
detail.Columns(“invoicedetailid”).Visible = False
‘detail.Columns(“comments”).Width = 300
detail.Columns(“EditLine”).VisibleIndex = 0
detail.Columns(“comments”).VisibleIndex = 10
detail.Columns(“DeleteLine”).VisibleIndex = 20
detail.ReadOnly = False
detail.DataRowTemplate = New CustomDataRow
Grid.DetailGridTemplates.Add(detail)
detail.Collapse()
Grid.EndInit()
End Sub
Imported from legacy forums. Posted by Greg (had 1223 views)
I figured it out by adding in this following line when the detail grid begins to build
Employees.ChildRelations.Add(New DataRelation(“Employee_Punches”, dSEmployees.Tables(“Employees”).Columns(“EmployeeID”), dSEmployees.Tables(“TimeClockPunches”).Columns(“EmployeeID”)))
Imported from legacy forums. Posted by Greg (had 1156 views)
-
AuthorPosts
- You must be logged in to reply to this topic.