Foxtable(狐表)用户栏目专家坐堂 → grid事件问题


  共有2640人关注过本帖树形打印复制链接

主题:grid事件问题

帅哥哟,离线,有人找我吗?
fendouww
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:312 积分:2519 威望:0 精华:0 注册:2019/7/19 13:09:00
grid事件问题  发帖心情 Post By:2021/2/19 16:57:00 [只看该作者]

加载表时我用以下代码绑定了单击表头的事件,当只有一张表时,运行完美,但当加载第二表/第三表时(也会执行一次此代码),单击表头事件就出现问题,会重复执行单击代码(和表的数量成正比),请问是哪里的问题

        For Each t As Table In Tables
            If senders.Contains(t.Name) Then
                t.grid.Name = t.Name
                addhandler t.grid.MouseEnterCell, addressof MouseEnterCellHandler
                addhandler t.grid.MouseLeaveCell, addressof MouseLeaveCellHandler
                addhandler t.grid.Click, addressof ClickHandler
            End If
        Next


 回到顶部
帅哥哟,离线,有人找我吗?
fendouww
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:312 积分:2519 威望:0 精华:0 注册:2019/7/19 13:09:00
  发帖心情 Post By:2021/2/19 16:58:00 [只看该作者]

以下是全局代码

Public headCol As Integer = -1

Public Sub MouseLeaveCellHandler(sender As object, e As C1.Win.C1FlexGrid.RowColEventArgs )
headcol = -1
End Sub

Public Sub MouseEnterCellHandler(sender As object, e As C1.Win.C1FlexGrid.RowColEventArgs )
If e.Row >= 0 AndAlso e.Row <= 1 Then
    headcol = e.Col
End If
End Sub
Public senders As String() = {"下单表","货期管理","生产跟进","核价单","大货进度","下单报价","报价单_Table1"}
Public Sub ClickHandler(sender As object, e As System.EventArgs)
If headcol <> -1 AndAlso senders.Contains(sender.name) Then
    Dim cname = Tables(sender.Name).Cols(headcol-1).Name
    Dim idx As Integer = headcol
    '  MessageBox.Show(sender.name & "-" & cname & "-" & idx & "-" & sender(0, idx))
    System.Threading.Thread.Sleep(100)
    Dim nms As String()
    Dim nn As String = ""
    If sender.name = "货期管理" AndAlso cname = "延期次数" Then
        nms = {"货期申请","提交延期单时间","延期责任方","生产主管","生产组长","设计师名字","淘宝销售","唯品会销售","第三方销售","大货延期原因","主管确认","主管确认时间","经理确认","经理","经理确认时间","销售确认","销售确认时间","面料确认","面料主管","面料确认时间","设计确认","设计确认时间","淘宝确认","淘宝确认时间","唯品会确认","唯品会确认时间","第三方确认","第三方确认时间","设计组长确认","设计组长","设计经理确认","设计经理"}
        nn = "延期"
    End If
    If sender.name = "生产跟进" AndAlso cname = "汇总" Then
        nms = {"淘宝","唯品会","第三方","均码F","XS","S","M","L","XL","XXL","XXXL","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44"}
        nn = "汇总"
    End If
    
    If sender.name = "大货进度" AndAlso cname = "状态" Then
        nms = {"分类","生产部","生产理单","设计师名字","品类"}
        nn = "状态"
    End If
    If sender.name = "大货进度" AndAlso cname = "货期" Then
        nms = {"最新货期","面料理单","单价_价格","单价_单位","面料类别","面料备注"}
        nn = "货期"
    End If
    If sender.name = "大货进度" AndAlso cname = "生产记录" Then
        nms = {"胚布","打色","染色日期","生产异常","进度备注","生产报告"}
        nn = "生产记录"
    End If
    If sender.name = "大货进度" AndAlso cname = "缸差记录" Then
        nms = {"头缸确认","记录时间","缸差异常","处理结果","最新状态"}
        nn = "缸差记录"
    End If
    If sender.name = "下单表" OrElse sender.name = "下单报价" Then
        If cname = "汇总" Then
            nms = {"均码F","XS","S","M","L","XL","XXL","XXXL","25","24","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","总计合计"}
            If sender(0, idx) = "汇总 +" OrElse sender(1, idx) = "汇总 +" Then
                For Each nm As String In nms
                    Tables(sender.name).Cols(nm).Visible = True
                Next
                sender(0, idx) = "汇总 -"
                sender(1, idx) = "汇总 -"
                Return
            Else
                nms = {"均码F","XS","S","M","L","XL","XXL","XXXL","25","24","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","总计合计","均码","淘宝_XS","淘宝_S","淘宝_M","淘宝_L","淘宝_XL","淘宝_XXL","淘宝_XXXL","淘宝_24","淘宝_25","淘宝_26","淘宝_27","淘宝_28","淘宝_29","淘宝_30","淘宝_31","淘宝_32","淘宝_33","淘宝_34","淘宝_35","淘宝_36","淘宝_37","淘宝_38","淘宝_39","淘宝_40","淘宝_41","淘宝_42","淘宝_43","淘宝_44","淘宝合计","均码1","WP_XS","WP_S","WP_M","WP_L","WP_XL","WP_XXL","WP_XXXL","WP_24","WP_25","WP_26","WP_27","WP_28","WP_29","WP_30","WP_31","WP_32","WP_33","WP_34","WP_35","WP_36","WP_37","WP_38","WP_39","WP_40","WP_41","WP_42","WP_43","WP_44","WP合计","均码2","京东_XS","京东_S","京东_M","京东_L","京东_XL","京东_XXL","京东_XXXL","京东_24","京东_25","京东_26","京东_27","京东_28","京东_29","京东_30","京东_31","京东_32","京东_33","京东_34","京东_35","京东_36","京东_37","京东_38","京东_39","京东_40","京东_41","京东_42","京东_43","京东_44","京东合计"}
                With DataTables(sender.name)
                    .DataCols("总计合计").Caption = "总计合计 +"
                    .BuildHeader()
                End With
                For Each nm As String In nms
                    Tables(sender.name).Cols(nm).Visible = False
                Next
                sender(0, idx) = "汇总 +"
                sender(1, idx) = "汇总 +"
                Return
            End If
        End If
        If cname = "总计合计" Then
            nms = {"均码","淘宝_XS","淘宝_S","淘宝_M","淘宝_L","淘宝_XL","淘宝_XXL","淘宝_XXXL","淘宝_24","淘宝_25","淘宝_26","淘宝_27","淘宝_28","淘宝_29","淘宝_30","淘宝_31","淘宝_32","淘宝_33","淘宝_34","淘宝_35","淘宝_36","淘宝_37","淘宝_38","淘宝_39","淘宝_40","淘宝_41","淘宝_42","淘宝_43","淘宝_44","淘宝合计","均码1","WP_XS","WP_S","WP_M","WP_L","WP_XL","WP_XXL","WP_XXXL","WP_24","WP_25","WP_26","WP_27","WP_28","WP_29","WP_30","WP_31","WP_32","WP_33","WP_34","WP_35","WP_36","WP_37","WP_38","WP_39","WP_40","WP_41","WP_42","WP_43","WP_44","WP合计","均码2","京东_XS","京东_S","京东_M","京东_L","京东_XL","京东_XXL","京东_XXXL","京东_24","京东_25","京东_26","京东_27","京东_28","京东_29","京东_30","京东_31","京东_32","京东_33","京东_34","京东_35","京东_36","京东_37","京东_38","京东_39","京东_40","京东_41","京东_42","京东_43","京东_44","京东合计"}
            nn = "总计合计"
        End If
        If sender.name = "下单报价" AndAlso cname = "报价" Then
            nms = {"面料分类","面料成分","工厂","货期","广告样时间","修改意见","面料信息","版型","上新时间","淘宝金额","唯品金额","京东金额","合计金额","类型","花型","细节","报销款号","淘宝销售","唯品会销售","第三方销售","授权号","生产周期","充绒量","毛领信息","合同号","最新货期","生产主管","生产组长","生产理单","生产跟单","订单分类","翻单类型"}
            nn = "报价"
        End If
    End If
    If sender.name = "核价单" OrElse sender.name = "报价单_Table1" Then
        If cname = "报价时间" Then
            nms = {"设计师","季节归属","来源","性别","推广方式","尺寸表","样衣图片","版单"}
            nn = "下单报价时间"
        End If
        If cname = "面料_品名" Then
            nms = {"面料_单价","面料_用料","撞拼布_单价","撞拼布_用料","里料_单价","里料_用料","胆布_单价","胆布_用量","羽绒_单价","羽绒_用量","毛领_长度厘米","毛领_宽度厘米","毛领_单价平方厘米","辅料_压胶","辅料_摇粒绒","辅料_手塞棉","辅料_仿丝棉","辅料_行棉","辅料_袋布","辅料_衬布","辅料_罗纹","辅料_横机","辅料_拉链","辅料_扣子","辅料_气眼","辅料_织标","辅料_织带","辅料_松紧橡筋","辅料_魔术贴","辅料_撞钉","辅料_帽绳配件","辅料_三标","辅料_线","辅料_其他"}
            nn = "面料品名"
        End If
    End If
    If nn > "" Then
        If sender(0, idx) = nn & " +" Then
            sender(0, idx) = nn & " -"
            sender(1, idx) = nn & " -"
            For Each nm As String In nms
                Tables(sender.name).Cols(nm).Visible = True
            Next
            Return
        Else
            sender(0, idx) = nn & " +"
            sender(1, idx) = nn & " +"
            For Each nm As String In nms
                Tables(sender.name).Cols(nm).Visible = False
            Next
            Return
        End If
    End If
End If
End Sub

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110443 积分:562081 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/2/19 17:31:00 [只看该作者]

代码放在什么事件的?

 回到顶部
帅哥哟,离线,有人找我吗?
fendouww
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:312 积分:2519 威望:0 精华:0 注册:2019/7/19 13:09:00
  发帖心情 Post By:2021/2/19 20:53:00 [只看该作者]

放在切换主表之后,也就是表加载后,我仔细找了原因,就是加载第二张表后,我单击表头,在全局代码会执行两次,三张表会执行三次,四张表4次....这是为何,我明明只单击了一次

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110443 积分:562081 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/2/20 9:25:00 [只看该作者]

放在切换主表之后,也就是表加载后,  --  1楼的代码具体是在哪个事件,能不能把名称说出来?

 回到顶部
帅哥哟,离线,有人找我吗?
fendouww
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:312 积分:2519 威望:0 精华:0 注册:2019/7/19 13:09:00
  发帖心情 Post By:2021/2/20 19:49:00 [只看该作者]

MainTableChanged

切换主表后执行,也就是MainTable发生变化后执行。
此事件无e参数,这是因为系统变量MainTable可以直接返回所选择的主表。


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110443 积分:562081 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/2/21 19:33:00 [只看该作者]

不能放在MainTableChanged事件,放到afteropenproject事件。

事件是可以重复绑定的,MainTableChanged事件每切换表都会触发一次,触发一次就绑定一次事件,比如切换表10次就会触发绑定10次事件,也就是全局代码每次都会触发执行10次,以此类推......

 回到顶部