Hi,
In the code below, I try to see if a certain column of a DataGridView was clicked, and run a report if so.
Private Sub dgv_Report_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgv_Report.CellMouseDoubleClick
Dim i As Integer = -1
Dim s As String = String.Empty
Try
If Not e.ColumnIndex < 0 And Not e.RowIndex < 0 And DrillDownColumns.Count > 0 Then
For Each ddc As DrillDownColumn In DrillDownColumns
s = ddc.TriggerColumn
i = CType(sender, DataGridView).Columns(columnName:=s).DisplayIndex
If i = e.ColumnIndex Then
For Each p As SqlParameter In ddc.Parameters
p.Value = CType(sender, DataGridView).Columns.Item(p.SourceColumn)
Next
RunSubReport(DDC:=ddc)
End If
Next
End If
Catch ex As Exception
EC(ex)
End Try
End Sub
The line:
i = CType(sender, DataGridView).Columns(columnName:=s).DisplayIndex
throws an
Quote:
Object reference not set to an instance of an object
error.
When I check in debug, the sender has 9 columns though, including a column by the name that I am testing with.
Can someone please explain this to me, or tell me what it is I am missing?
Regards,
Johan
What I have tried:
MsgBox(CType(sender, DataGridView).Columns.Count.ToString) --> returns a number > 0
I have checked that the column name that I am searching for actually exists.
Otherwise staring myself blind I guess.