I have a datagride in, let's say frmMain, but how do I access this datagrid's properties in another class, let's say clsComputer? When I'm creating a public function to load the data from a datbase mdb file into frmMain's datagrid1, how do I do that? Here's what I have tried access in the clsComputer class:
Many thanks in advance!
ljCharlie
But I received an error:Public Class clsComputer
Private Shared mdbPath As String = Application.StartupPath & "\Computers.mdb"
Dim clsMain As frmMain
Dim CompDG As DataGrid = clsMain.dgComputer
Public Function ComputerDG()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & mdbPath
Dim strSQL As String = "SELECT * FROM Computer"
Dim compDataAdapter As New OleDbDataAdapter(strSQL, strConn)
Dim compDataSet As New DataSet()
Dim ts As New DataGridTableStyle()
compDataSet.Clear()
compDataAdapter.Fill(compDataSet, "CompDevices")
CompDG.DataSource = compDataSet.Tables!CompDevices
'GET CURRENCY MANAGER
Dim cm As CurrencyManager
cm = CType(clsMain.BindingContext(compDataSet.Tables!CompDevices), CurrencyManager)
'CREATE DATAGRIDSTYLES AND MODIFY
ts = New DataGridTableStyle(cm)
ts.GridColumnStyles(0).HeaderText = "Serial#"
ts.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
ts.GridColumnStyles(0).ReadOnly() = True
ts.GridColumnStyles(1).Alignment = HorizontalAlignment.Center
ts.GridColumnStyles(1).ReadOnly() = True
ts.GridColumnStyles(2).Alignment = HorizontalAlignment.Center
ts.GridColumnStyles(2).ReadOnly() = True
ts.GridColumnStyles(3).HeaderText = "Date Purchased"
ts.GridColumnStyles(3).Alignment = HorizontalAlignment.Center
ts.GridColumnStyles(3).ReadOnly() = True
ts.GridColumnStyles(3).Width() = 100
CompDG.TableStyles.Add(ts)
End Function
End Class
If I declared Dim clsMain As frmMain as Dim clsMain As New frmMain then I don't receive any error, but the problem now is that the data does not load from the database mdb file into the datagrid in the frmMain form.An unhandled exception of type System.NullReferenceException occurred in Devices.exe
Additional information: Object reference not set to an instance of an object.
Many thanks in advance!
ljCharlie