【发布时间】:2021-12-30 14:12:57
【问题描述】:
我真的可以在这里得到一些帮助。
我有一个 List(Of String),其中包含以下内容:
A/A
A/B
空调
B/a
乙/乙
B/C
C/a
C/b
转/转
..等等。
我正在尝试在按第一个字母分组的 TableLayoutPanel 中创建控件,以使布局看起来像这样。
标题 A
标签a |文本框
标签 b |文本框 b
标签 c |文本框 c
标题 B
标签a |文本框
标签 b |文本框 b
标签 c |文本框 c
标题 C
标签a |文本框
标签 b |文本框 b
标签 c |文本框 c
我当前的代码对列表进行排序并创建控件:
For Each item In _List
TableLayoutPanel1.Controls.Add(New Label With {
.Name = cc.ToString,
.Text = SplitContentControl(cc.ToString, ""),
.Height = 20,
.Font = New Font("Segoe UI", 12,
FontStyle.Bold)
})
TableLayoutPanel1.Controls.Add(New TextBox With {.Height = 20,
.Font = New Font("Segoe UI", 12,
FontStyle.Bold)})
Next
我尝试过像这样创建一个 Dictionary(Of String, String):
Dim dict As Dictionary(Of String, String) = ccs.ToDictionary(Function(x) x.split("/")(0), Function(y) y.split("/")(1))
但当然不能这样做,因为这会产生重复。
我还尝试使用 Split("/") 和 Lambda 表达式创建一个新的 List(Of ControlID),其中 ControlID 是类
Public Class ControlID
Public ControlHead as String
Public ControlName as String
End Class
但无论我尝试什么,我似乎都无法让 Lambda 为我工作。
如果有人有解决方案,请提供帮助。我将不胜感激。
【问题讨论】: