作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够有两个组合框,其中一个是第二个组合框的父级或所有者。这意味着每当我在第一个 ComboBox
中选择一个值时,第二个 ComboBox
就会过滤其结果以显示与第一个 ComboBox
相关的相应值>.
例如:
注意:此示例已通过编程方式完成...我想了解如何使用 Visual Studio 的用户界面来完成此操作
<小时/>我有一个包含两个数据表的数据集,如下所示:
如您所见,我的 BakerySubSectionsTableAdapter
中有一个名为 @FK_BakerySection 的参数。我想将其链接到 BakerySection
PK_BakerySection 属性。
这是我当前的结果:
在我的 TableAdapter 中使用以下查询:
那么...我们如何使用用户界面为参数设置值?
最佳答案
如果您在两个表之间添加DataRelation
,这很容易(IIRC,您可以简单地在数据集设计器中执行此操作)。
然后您只需将第二个 ComboBox
的 DisplayMember
设置为 ParentTable.NameOfRelation.NameToDisplay
。
这是一个完整的小示例:
<小时/>
Dim data = New DataSet()
Dim section = data.Tables.Add("Section")
section.Columns.Add("ID", GetType(Integer))
section.Columns.Add("Name", GetType(String))
Dim sub_section = data.Tables.Add("SubSection")
sub_section.Columns.Add("ID", GetType(Integer))
sub_section.Columns.Add("Name", GetType(String))
sub_section.Columns.Add("Section", GetType(Integer))
section.Rows.Add(New Object() {1, "Foo"})
section.Rows.Add(New Object() {2, "Bar"})
sub_section.Rows.Add(New Object() {1, "Sub Foo", 1})
sub_section.Rows.Add(New Object() {2, "Another Sub Foo", 1})
sub_section.Rows.Add(New Object() {3, "Sub Bar", 2})
sub_section.Rows.Add(New Object() {4, "bar bar bar", 2})
sub_section.Rows.Add(New Object() {5, "more bar", 2})
section.ChildRelations.Add("SectionToSub", section.Columns("ID"), sub_section.Columns("Section"))
Dim f = New Form()
Dim c1 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.Name", _
.ValueMember = "Id" _
}
Dim c2 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.SectionToSub.Name", _
.ValueMember = "Id" _
}
Dim fl = New FlowLayoutPanel()
fl.Controls.Add(c1)
fl.Controls.Add(c2)
f.Controls.Add(fl)
f.ShowDialog()
只需确保您的 BakerySubSections
已完全填充(无需参数)。
关于vb.net - 如何为 TableAdapter 参数设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23390646/
我是一名优秀的程序员,十分优秀!