Datagridview点击事件,发件人似乎什么都没有 [英] Datagridview click event, sender appears to be nothing

查看:84
本文介绍了Datagridview点击事件,发件人似乎什么都没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在下面的代码中,我尝试查看是否单击了DataGridView的某个列,如果是,则运行报告。



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
            'Get the drill down report for the column that was double clicked
            If Not e.ColumnIndex < 0 And Not e.RowIndex < 0 And DrillDownColumns.Count > 0 Then
                For Each ddc As DrillDownColumn In DrillDownColumns
                    'Check if one of the trigger columns was clicked
                    s = ddc.TriggerColumn
                    i = CType(sender, DataGridView).Columns(columnName:=s).DisplayIndex
                    If i = e.ColumnIndex Then
                        'Get the parameters
                        For Each p As SqlParameter In ddc.Parameters
                            p.Value = CType(sender, DataGridView).Columns.Item(p.SourceColumn)
                        Next
                        'Run the drill down report
                        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

抛出

引用:

对象引用未设置为对象的实例

Object reference not set to an instance of an object

错误。



当我签入调试时,发件人有9列,包括我正在测试的名称列。



有人可以向我解释这个,或者告诉我它是什么我我不见了?



问候,

Johan



什么我试过了:



MsgBox(CType(sender,DataGridView).Columns.Count.ToString) - >返回一个数字> 0



我已经检查过我要搜索的列名实际存在。



否则盯着看我猜对了。

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.

推荐答案

Doh!



搜索字符串:2017_2_Sales - >列名:2017_02_Sales
Doh!

Search string: 2017_2_Sales --> column name: 2017_02_Sales


这篇关于Datagridview点击事件,发件人似乎什么都没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆