I've created a Combobox
and the list selections are being populated by a DataTable
. I can populate it with no problems, but I need to add a default item for the list before the results from the DataTable appears.
我创建了一个Combobox,列表选择由DataTable填充。我可以毫无问题地填充它,但我需要在显示DataTable的结果之前为列表添加一个默认项。
The list should contain:
该清单应包含:
All Rooms and Facilities
Class Room
Laboratory
PE Facility
THE Facility
Drawing Room
Library
But I'm always getting:
但我总是得到:
I've been using this link as my resources: https://msdn.microsoft.com/en-us/library/aa983551.aspx
我一直在使用此链接作为我的资源:https://msdn.microsoft.com/en-us/library/aa983551.aspx
And here's my code:
这是我的代码:
cboByRoomType.Items.Insert(0, "All Rooms and Facilities")
With cboByRoomType
.DataSource = tempDTRoomType
.DisplayMember = "Description"
.ValueMember = "Room Type ID"
.SelectedIndex = 0
End With
Also, I already tried to add the default item using the Items in the Properties Window
, still no good.
此外,我已经尝试使用属性窗口中的项目添加默认项目,仍然没有好处。
1 个解决方案
#1
Try replacing your first row with this (which probably has a more compact form):
尝试用这个替换你的第一行(可能有一个更紧凑的形式):
tempDTRoomType.Rows.InsertAt(tempDTRoomType.NewRow(), 0)
tempDTRoomType.Rows(0).Item("Description") = "All Rooms and Facilities"
tempDTRoomType.Rows(0).Item("Room Type ID") = 0
#1
Try replacing your first row with this (which probably has a more compact form):
尝试用这个替换你的第一行(可能有一个更紧凑的形式):
tempDTRoomType.Rows.InsertAt(tempDTRoomType.NewRow(), 0)
tempDTRoomType.Rows(0).Item("Description") = "All Rooms and Facilities"
tempDTRoomType.Rows(0).Item("Room Type ID") = 0