May this will Solve Your problem.
As Per What I did
I have two forms Form1 and Form2
Form1 has Got the CR viewer and Form2 A gridview With Select button .I will also State that how I have Added The gridview button and Coulumns here .In Form2
I wrote a function to Display the Data from Db and to show it in the GridView Like :
Public Sub dataDisp()
Dim sd As New SqlDataAdapter("Select * from Product", Mycon.con())
Dim dt As New DataTable
sd.Fill(dt)
If dt.Rows.Count > 0 Then
dGview.DataSource = dt
Dim dgButtonColumn As New DataGridViewButtonColumn
dgButtonColumn.HeaderText = ""
dgButtonColumn.UseColumnTextForButtonValue = True
dgButtonColumn.Text = "Select"
dgButtonColumn.Name = "Select"
dgButtonColumn.ToolTipText = "Select"
dgButtonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader
dgButtonColumn.FlatStyle = FlatStyle.System
dgButtonColumn.DefaultCellStyle.BackColor = Color.Gray
dgButtonColumn.DefaultCellStyle.ForeColor = Color.White
dGview.Columns(0).Visible = False
dGview.Columns.Add(dgButtonColumn)
End If
End Sub
After That i call This Function On the FormLoad Event or you Can take A button to Call This Function to Load the Data in the GridView.
Here I have Used A database table named "Product"
And then under dGview_CellContentClick Event checked that if Select button is Pressed Like :
Private Sub dGview_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dGview.CellContentClick
If sender.Columns(e.ColumnIndex).Name = "Select" Then
Form1.Show()
End If
End Sub
And if the Select Button is Pressed Call the Form1 or Say the Form Containing the CR viewer
And Now how to Load the report So, here Also I used a Function To Extract the Data form Db and to load it in the Report Like:
Private Sub MyReportCRYSTAL()
Dim sd As New SqlDataAdapter("Select * from Product where Product_id='" & Form2.dGview.SelectedCells.Item(0).Value & "'", Mycon.con())
Dim dt As New DataTable
sd.Fill(dt)
If dt.Rows.Count > 0 Then
Dim pr As New ProductReport()
pr.SetDataSource(dt)
CrystalReportViewer1.ReportSource = pr
CrystalReportViewer1.RefreshReport()
End If
End Sub
Here ProductReport is the CrystalReport what i ihave Designed taking the Fields from the Table Product
Call This Function On the Form Load Event.So that whenever You click the Select Button this Form opens and the Required Report also get loaded on the form load
Also I assume that You have the Id Field in the gridview which I am passing in the where Clause of the Select Query as "Form2.DataGridViewName.SelectedCells.Item(0).Value"
myCon is the Connection Class.
That's All.Try This Will Work Fine