提问人:Cnewbster 提问时间:2/14/2023 最后编辑:Cnewbster 更新时间:2/14/2023 访问量:33
在VB中将组合框的值更改为另一个值
Changing Value of Combo Box to another Value in VB
问:
我正在尝试更改组合框值“Black Shredded - 7.90”的值,以便在选择时仅显示“Black Shredded”
Dim intIndex As Integer
Dim strString1 As String
Dim strString2 As String
strString1 = cboProduct.SelectedItem
intIndex = strString1.IndexOf(" ")
strString2 = strString1.Remove(intIndex + 9)
If cboProduct.SelectedIndex = 0 Then
cboProduct.Text = strString2
End If
我浏览了这些值,它们按应有的方式显示,但它并没有改变组合框值,我可能做错了什么?
答:
0赞
jmcilhinney
2/14/2023
#1
如果您首先添加了 ,则需要将现有项目替换为新值。这:Strings
ComboBox
cboProduct.Text = strString2
应该是这样的:
cboProduct.Items(cboProduct.SelectedIndex) = strString2
您可以只使用 而不是 ,因为您已经确认这是当时的索引。0
cboProduct.SelectedIndex
设置该属性完全不会影响这些项。如果设置为,则将显示指定的文本,但不会选择任何项目。如果设置为,则将选择包含该文本的项目(如果存在)。无论哪种方式,都不会添加或更改任何项目。Text
DropDownStyle
DropDown
DropDownStyle
DropDownList
评论