以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何实现多个字段选择显示或隐藏?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=175241)

--  作者:cnsjroom
--  发布时间:2022/2/25 3:10:00
--  如何实现多个字段选择显示或隐藏?

如何实现多个字段选择显示或隐藏?想实现选择字段后,点击显示或隐藏   对应的被选择字段就实现显示或隐藏


图片点击可在新窗口打开查看此主题相关图片如下:1111.png
图片点击可在新窗口打开查看
显示或隐藏按钮代码该什么写呢?
--  作者:有点蓝
--  发布时间:2022/2/25 8:30:00
--  

--  作者:cnsjroom
--  发布时间:2022/2/25 9:48:00
--  回复:(有点蓝)http://www.foxtable.com/webhelp/to...

老师看了帮助 参照做成如下:

显示按钮代码:

Dim ckl As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
Dim tb As WinForm.Table = Forms("组合筛选").Controls("Table1")
Dim nms As New List(of String)
For i As Integer = 0 To ckl.Items.count - 1  \'获取已经勾选的列
    If ckl.GetItemChecked(i) Then
        nms.Add(ckl.Items(i))
    End  If
Next
If nms.Count = 0 Then
    MessageBox.Show("至少要选择一列","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
For i As Integer = 0 To nms.count -1
    For Each nm As String In nms
        tb.Table.Cols(nm).Visible = True
        tb.Table.Cols(nm).PrintWidth=80
    Next
Next


Dim bbt As WinForm.Button = Forms("组合筛选").Controls("Button1")
bbt.PerformClick

实现效果: 【为什么列宽会变化与其他不协调?】

 
此主题相关图片如下:22.png
按此在新窗口浏览图片

 

隐藏按钮代码:

Dim ckl As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
Dim tb As WinForm.Table = Forms("组合筛选").Controls("Table1")
Dim nms As New List(of String)
For i As Integer = 0 To ckl.Items.count - 1  \'获取已经勾选的列
    If ckl.GetItemChecked(i) Then
        nms.Add(ckl.Items(i))
    End  If
Next
If nms.Count = 0 Then
    MessageBox.Show("至少要选择一列","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
For i As Integer = 0 To nms.count -1
    For Each nm As String In nms
        tb.Table.Cols(nm).Visible = false
    Next
Next


Dim bbt As WinForm.Button = Forms("组合筛选").Controls("Button1")
bbt.PerformClick

 

实现效果:

 


此主题相关图片如下:21.png
按此在新窗口浏览图片

Button1按钮事件代码:【实现表列宽自动充满窗体】

Dim ts() As String = {"table1"}

For Each s As String In ts
    Dim t As Table = e.Form.controls(s).Table
    Dim width As Double = t.grid.width - t.grid.cols(0).widthdisplay
    Dim sum As Double = 0
    For Each c As object In t.grid.cols
        If c.index > 0 AndAlso c.visible = True Then
            sum += c.widthdisplay
        End If
    Next
    For Each c As object In t.grid.cols
        If c.index > 0 AndAlso c.visible = True Then
            c.width = c.widthdisplay/sum*width
        End If
    Next
Next

 


--  作者:有点蓝
--  发布时间:2022/2/25 9:52:00
--  

PrintWidth

返回或设置列宽,单位为毫米
例如将数量列的列宽设为15毫米:

Tables("订单").Cols("数量").PrintWidth = 15


--  作者:cnsjroom
--  发布时间:2022/2/25 10:55:00
--  回复:(有点蓝)PrintWidth返回或设置列宽,单位为毫...

 

 

tb.Table.Cols(nm).PrintWidth=80

把这个注释了 貌似也一样

 

 

貌似下面的这个没有起作用?因为显示或隐藏的代码运行后会运行如下代码

Dim ts() As String = {"table1"}

For Each s As String In ts
    Dim t As Table = e.Form.controls(s).Table
    Dim width As Double = t.grid.width - t.grid.cols(0).widthdisplay
    Dim sum As Double = 0
    For Each c As object In t.grid.cols
        If c.index > 0 AndAlso c.visible = True Then
            sum += c.widthdisplay
        End If
    Next
    For Each c As object In t.grid.cols
        If c.index > 0 AndAlso c.visible = True Then
            c.width = c.widthdisplay/sum*width
        End If
    Next
Next


--  作者:有点蓝
--  发布时间:2022/2/25 11:01:00
--  
如果要平分列宽参考

Dim lst As new List(of String)

Dim ct As WinForm.Table = e.Form.Controls("Table1")
Dim t As Table = ct.Table
For Each c As Col In t.Cols
    If c.Visible Then lst.Add(c.Name)
Next

Dim w As Integer = (ct.Width-30) / lst.Count
t.SetColVisibleWidth(String.Join("|" & w & "|",lst.ToArray) & "|" & w)

不要动不动就用一些底层的用法,有问题我们也不会提供支持的

--  作者:cnsjroom
--  发布时间:2022/2/25 11:12:00
--  回复:(有点蓝)如果要平分列宽参考Dim lst As new L...

ok  谢谢老师