malanois
asked on
Table is not valid for dataset
I am currently manually filling a dataset and datagrid and it is working fine. On another form I have a VB.net filled datagrid. I am trying to get the mouse event on the manually filled datagrid.
Here is mouse event for form1, THIS WORKS, THE DataSET is created from vb.net wizard
Private Sub datagridClick(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles DataGrid.MouseDown
Dim mouseClick As DataGrid.HitTestInfo
Dim descIndex As Integer
Dim picIndex As Integer
If e.Button = MouseButtons.Left Then
dgObservation = CType(sender, DataGrid)
mouseClick = DataGrid.HitTest(e.X, e.Y)
gridRow = mouseClick.Row
'Get variable of selected rows
On Error Resume Next
PnIndex = Me.DbDataSet.T_PARTS.Colum ns.IndexOf ("TRDB_PN" )
Pnname = Me.DbDataSet.T_PARTS.Rows( gridRow)(P nIndex).To String
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
This is the manually created one on form 2
It fills the dataset correctly.
Dim sConn As String = "Provider=Microsoft.Jet.OL EDB.4.0;" & _
"Data Source=" & DBNAME & ";Persist Security Info=False"
Dim sSQL1 As String = "SELECT DISTINCT T_RESOURCES.RESOURCE_ID, T_RESOURCES.RESOURCE_TITLE , T_RESOURCES." & _ "RESOURCE_LINK_VIEW, T_RESOURCES_GRP_XREF.GRP_I D, T_RESOURCES_GRP_XREF.SUB_G RP_ID" & _ ", T_RESOURCES_GRP_XREF.XREF_ SOURCE FROM (T_RESOURCES INNER JOIN T_RESOURCES_GRP_" & _
"XREF ON T_RESOURCES.RESOURCE_ID = T_RESOURCES_GRP_XREF.RESOU RCE_ID) WHERE (T_RESOURCES_GRP_XREF.GRP_ ID = '" & libstring & "')"
oleDA1 = New OleDbDataAdapter(sSQL1, sConn)
oleDA1.Fill(manset)
Dim tsm
Me.ManDataGrid.DataSource = manset
Me.ManDataGrid.DataMember = "Table"
tsm = New DataGridTableStyle
tsm.mappingname = "Table"
' Create columns
Dim DataColParent As New DataGridTextBoxColumn
DataColParent.HeaderText = "RESOURCE"
DataColParent.MappingName = "RESOURCE_ID"
'DataColParent.NullText = "NO PARTS"
DataColParent.Width = 89
tsm.GridColumnStyles.Add(D ataColPare nt)
------------------ This is where the error comes that I cannot compile
Private Sub datagridClick(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles ManDataGrid.MouseDown
Dim mouseClick As DataGrid.HitTestInfo
Dim descIndex As Integer
Dim picIndex As Integer
If e.Button = MouseButtons.Left Then
dgObservation = CType(sender, DataGrid)
mouseClick = ManDataGrid.HitTest(e.X, e.Y)
gridrow = mouseClick.Row
VVVV---------------------- ---------- --------Ta ble is not a member of System.Data.Dataset
IDIndex = Me.manset.Table.Columns.In dexOf("Res ouce_ID")
ID = Me.manset.m.Rows(gridrow)( IDIndex).T oString
I think it is just mapping Table as the table for manset, or binding the name to it, I am lost
Thanks, Malanois
Here is mouse event for form1, THIS WORKS, THE DataSET is created from vb.net wizard
Private Sub datagridClick(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles DataGrid.MouseDown
Dim mouseClick As DataGrid.HitTestInfo
Dim descIndex As Integer
Dim picIndex As Integer
If e.Button = MouseButtons.Left Then
dgObservation = CType(sender, DataGrid)
mouseClick = DataGrid.HitTest(e.X, e.Y)
gridRow = mouseClick.Row
'Get variable of selected rows
On Error Resume Next
PnIndex = Me.DbDataSet.T_PARTS.Colum
Pnname = Me.DbDataSet.T_PARTS.Rows(
--------------------------
This is the manually created one on form 2
It fills the dataset correctly.
Dim sConn As String = "Provider=Microsoft.Jet.OL
"Data Source=" & DBNAME & ";Persist Security Info=False"
Dim sSQL1 As String = "SELECT DISTINCT T_RESOURCES.RESOURCE_ID, T_RESOURCES.RESOURCE_TITLE
"XREF ON T_RESOURCES.RESOURCE_ID = T_RESOURCES_GRP_XREF.RESOU
oleDA1 = New OleDbDataAdapter(sSQL1, sConn)
oleDA1.Fill(manset)
Dim tsm
Me.ManDataGrid.DataSource = manset
Me.ManDataGrid.DataMember = "Table"
tsm = New DataGridTableStyle
tsm.mappingname = "Table"
' Create columns
Dim DataColParent As New DataGridTextBoxColumn
DataColParent.HeaderText = "RESOURCE"
DataColParent.MappingName = "RESOURCE_ID"
'DataColParent.NullText = "NO PARTS"
DataColParent.Width = 89
tsm.GridColumnStyles.Add(D
------------------ This is where the error comes that I cannot compile
Private Sub datagridClick(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles ManDataGrid.MouseDown
Dim mouseClick As DataGrid.HitTestInfo
Dim descIndex As Integer
Dim picIndex As Integer
If e.Button = MouseButtons.Left Then
dgObservation = CType(sender, DataGrid)
mouseClick = ManDataGrid.HitTest(e.X, e.Y)
gridrow = mouseClick.Row
VVVV----------------------
IDIndex = Me.manset.Table.Columns.In
ID = Me.manset.m.Rows(gridrow)(
I think it is just mapping Table as the table for manset, or binding the name to it, I am lost
Thanks, Malanois
try me.manset.tables(0).column s ... etc
Or me.manset.tables("Table"). columns.In dexOf("Res ource_ID")
The problem with your code is that you are not using a strongly typed generated dataset, therefore you cannot reference the dataset table via the property (.Table). You could do the same by manually adding a Dataset (xsd) to your project and declaring manset as the custom dataset. Or using the one generated in the form.
The problem with your code is that you are not using a strongly typed generated dataset, therefore you cannot reference the dataset table via the property (.Table). You could do the same by manually adding a Dataset (xsd) to your project and declaring manset as the custom dataset. Or using the one generated in the form.
Oh yeah and you can skip the index part as follows:
IDIndex = Me.manset.Table.Columns.In dexOf("Res ouce_ID")
ID = Me.manset.m.Rows(gridrow)( IDIndex).T oString
would be:
ID = Me.manset.m.Rows(gridrow)( "Resource_ ID").ToStr ing
Note: You can look in the Windows Generated Code section to see how the wizard generated code works.
IDIndex = Me.manset.Table.Columns.In
ID = Me.manset.m.Rows(gridrow)(
would be:
ID = Me.manset.m.Rows(gridrow)(
Note: You can look in the Windows Generated Code section to see how the wizard generated code works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.