以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于CheckedListBox控件  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=110635)

--  作者:裴保民
--  发布时间:2017/12/6 20:00:00
--  关于CheckedListBox控件
窗体上有一个CheckedListBox控件,我想根据登录者的角色不同加载窗体后加载不同的列。
我在窗体的AfterLoad事件中写了如下代码:运行后是加载所有的列,怎样隐藏指定列呢?

Dim lieming As WinForm.CheckedListBox = e.Form.Controls("lieCheckedListBox")
For Each c As Col In Tables("机具库存资料").cols
            s=s &"|"& c.Name
        Next
        lieming.ComboList=s
e.form.Controls("Table1").Table.DataSource =DataTables("机具库存资料")
e.form.controls("Table1").Table.Filter = Tables("机具库存资料").Filter

[此贴子已经被作者于2017/12/6 20:00:21编辑过]

--  作者:有点甜
--  发布时间:2017/12/6 20:34:00
--  

参考daim

 

Dim lieming As WinForm.CheckedListBox = e.Form.Controls("lieCheckedListBox")
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "第一列" orelse c.name = "第二列" Then
        If _username = "张三" Then
            s=s &"|"& c.Name
        End If
    Else
        s=s &"|"& c.Name
    End If
Next

lieming.ComboList=s
e.form.Controls("Table1").Table.DataSource =DataTables("机具库存资料")
e.form.controls("Table1").Table.Filter = Tables("机具库存资料").Filter


--  作者:裴保民
--  发布时间:2017/12/6 21:08:00
--  
老师我是想实现当登录的角色是“系统管理员”的身份时要加载“电话号码”、“第二电话号码”列和其他列,如果是输入操作员的身份登录的系统时要加载“电话号码掩码”、“第二电话号码掩码”列和其他列,怎么处理呢?
[此贴子已经被作者于2017/12/6 21:11:17编辑过]

--  作者:有点甜
--  发布时间:2017/12/6 21:22:00
--  

Dim lieming As WinForm.CheckedListBox = e.Form.Controls("lieCheckedListBox")
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" orelse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            s=s &"|"& c.Name
        End If
    ElseIf c.name = "电话号码掩码" orelse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            s=s &"|"& c.Name
        End If

    Else
        s=s &"|"& c.Name
    End If
Next

lieming.ComboList=s
e.form.Controls("Table1").Table.DataSource =DataTables("机具库存资料")
e.form.controls("Table1").Table.Filter = Tables("机具库存资料").Filter


--  作者:裴保民
--  发布时间:2017/12/12 8:51:00
--  
甜老师,这个窗体中还有一个副本表,怎么同时将副本表随着登录账户角色变化而变化呢?副本表的中的列变化规则同CheckedListBox控件中列的规则。
--  作者:有点甜
--  发布时间:2017/12/12 9:11:00
--  
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" OrElse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    ElseIf c.name = "电话号码掩码" OrElse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    Else
        c.visible = True
    End If
Next

--  作者:裴保民
--  发布时间:2017/12/12 9:18:00
--  

Dim lieming As WinForm.CheckedListBox = e.Form.Controls("lieCheckedListBox")
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" orelse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            s=s &"|"& c.Name
        End If
    ElseIf c.name = "电话号码掩码" orelse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            s=s &"|"& c.Name
        End If

    Else
        s=s &"|"& c.Name
    End If
Next

lieming.ComboList=s
e.form.Controls("Table1").Table.DataSource =DataTables("机具库存资料")
e.form.controls("Table1").Table.Filter = Tables("机具库存资料").Filter

甜老师和这段代码差不多。都是在AfterLoad事件中写代码,能公用这段代码吗?

还是在他下面加入以下代码呢?

For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" OrElse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    ElseIf c.name = "电话号码掩码" OrElse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    Else
        c.visible = True
    End If
Next


--  作者:有点甜
--  发布时间:2017/12/12 9:45:00
--  
可以分开写,也可以合并起来写。你就分开写吧。
--  作者:裴保民
--  发布时间:2017/12/12 9:55:00
--  
甜老师一下写的代码对吗?
Dim lieming As WinForm.CheckedListBox = e.Form.Controls("lieCheckedListBox")
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" orelse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            s=s &"|"& c.Name
        End If
    ElseIf c.name = "电话号码掩码" orelse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            s=s &"|"& c.Name
        End If
    Else
        s=s &"|"& c.Name
    End If
Next
For Each c As Col In Tables("机具库存资料").cols
    If c.name = "电话号码" OrElse c.name = "第二电话号码" Then
        If _userroles = "系统管理员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    ElseIf c.name = "电话号码掩码" OrElse c.name = "第二电话号码掩码" Then
        If _userroles = "操作员" Then
            c.visible = True
        Else
            c.visible = False
        End If
    Else
        c.visible = True
    End If
Next
lieming.ComboList=s
e.form.Controls("Table1").Table.DataSource =DataTables("机具库存资料")
e.form.controls("Table1").Table.Filter = Tables("机具库存资料").Filter


--  作者:有点甜
--  发布时间:2017/12/12 9:58:00
--  
差不多,有什么问题?