Click here to Skip to main content
16,020,677 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB
daJoin = New OleDbDataAdapter("SELECT Company.CompanyID, Company.CompanyName, Product.ProductID, Product.ProductDesc, Product.RawMatDesc FROM (Product " &
                                      "INNER JOIN Company ON Company.CompanyID=Product.CompanyID)", con)
        daJoin.Fill(dsJoin, "Product")
        con.Close()   
        dgvProdView.DataSource = dsJoin.Tables("Product")


What you are seeing above this is my code that will combine datatable Product and Company into 1 datagridview.

The next thing I want to do is to get the exact displayed data using the datagridview event cellmouseclick.

VB
Private Sub btnSelProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelProd.Click
    indexProd = dgvProdView.CurrentRow.Index
    txtProdDesc.Text = ds.Tables("Product").Rows(indexProd).Item("ProductDesc")
    txtRawMatDesc.Text = ds.Tables("Product").Rows(indexProd).Item("RawMatDesc")
End Sub


The codes there worked perfectly fine for me. it transfers the exact display into my datatable but when I added another statement.

VB
Private Sub btnSelProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelProd.Click
    indexProd = dgvProdView.CurrentRow.Index
'I added txtComp to get the Company name of the joined table   
 txtCompName.Text = ds.Tables("Company").Rows(indexProd).Item("CompanyName")
    txtProdDesc.Text = ds.Tables("Product").Rows(indexProd).Item("ProductDesc")
    txtRawMatDesc.Text = ds.Tables("Product").Rows(indexProd).Item("RawMatDesc")
End Sub


When I tried to run it and clicked the datagridview, it did'not gave me the displayed companyname but rather it gave me a Companyname that was not even in the joined table display.

Need help mates.
Posted
Comments
Ralf Meier 21-Jul-15 5:17am    
Where do you use the Event "CellMouseClick" ?
Which method ?
Jake Robert 21-Jul-15 19:56pm    
I use the cell mouseclick to get the displayed data in the datagridview.
So when I single-clicked a dataset in the datagridview, it will transfer the value of a single row into the textbox.
Ralf Meier 22-Jul-15 0:38am    
Thas wasn't my question ...
I wanted to see the method and it's Connection to the Event.
Could you improve your question with this part ?

1 solution

I now know what is the problem silly me >.<<br mode="hold" />
"dsJoin" this code is what I am lacking. I forget that I have 2 Datasets being called inside the form. Thanks though :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900