Foxtable(狐表)用户栏目专家坐堂 → 关于自动调节窗体表的列宽


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

主题:关于自动调节窗体表的列宽

帅哥,在线噢!
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/20 14:51:00 [显示全部帖子]

只能平分各列的宽度

SizeChanged事件

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)

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/20 15:33:00 [显示全部帖子]

隐藏后调用2楼的代码

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/20 17:05:00 [显示全部帖子]


 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/20 21:15:00 [显示全部帖子]

Dim lst As new List(of String)
lst.AddRange({"第五列","第六列"})
Dim ct As WinForm.Table = e.Form.Controls("Table1")
Dim t As Table = ct.Table
'Dim t As Table = Tables("表A")
Dim str As String
Dim w As Integer = 0
For Each c As Col In t.Cols
    If c.Visible Then
        If lst.Contains(c.Name) Then
            str = str & "|" & c.Name & "|[width]"
        Else
            If c.Width = -1 Then
                str = str & "|" & c.Name & "|98"
                w += 98
            Else
                str = str & "|" & c.Name & "|" & c.Width
                w += c.Width
            End If
        End If
    End If
Next

Dim w2 As Integer = (ct.Width-30- w) / lst.Count
str = str.trim("|").Replace("[width]",w2)
t.SetColVisibleWidth(str)

 回到顶部