DropDownList向上显示

时间:2015-07-16 15:12:44

标签: vb.net drop-down-menu list.selectedvalue

我认为这是一个简单的修复,但没有碰到它。

如果空的newListItem为.Selected = true,我的下拉列表将向上而不是向下显示选项。

有没有办法让列表向下拉?

我的SQL语句按字母顺序排序(因此计算机位于顶部)。

OracleDataAdapterAds1.Fill(DsAds, "TABLE NAME")
CategoryListBox.DataSource = DsAds
CategoryListBox.DataMember = "TABLE NAME"
CategoryListBox.DataBind()
Dim newListItem As ListItem
newListItem = New ListItem("", "")
newListItem.Selected = True
CategoryListBox.Items.Add(newListItem)

仅供参考 - 如果.Selected = false向下显示

当它向上时:

enter image description here

1 个答案:

答案 0 :(得分:3)

因为所选项目是列表中的最后一项。将项目插入顶部

CategoryListBox.Items.Insert(0, newListItem);

此外,根据您的情况,插入一个emtpy项目并不是一个好主意,特别是当控件是数据绑定时。 您可以不选择列表框,如下所示:

CategoryListBox.SelectedIndex = -1;