当选择了一个单选按钮时,我编写了一小段代码来更改组合框的显示成员。我遇到的唯一问题是,当我在单选按钮之间切换时,组合框消失然后在一秒钟之后返回,有没有办法解决这个问题。
Private Sub SearchOptionChange(sender As Object,e As EventArgs)处理RBExchange.CheckedChanged,RBPostcode.CheckedChanged
Dim RB As RadioButton = CType(sender, RadioButton)
If RB.Name = "RBExchange" AndAlso RB.Checked Then
ComboBox1.DisplayMember = "Exchange"
ComboBox1.Text = ""
ElseIf RB.Name = "RBPostcode" AndAlso RB.Checked Then
ComboBox1.DisplayMember = "Postcode"
ComboBox1.Text = ""
End If
End Sub
答案 0 :(得分:0)
我使用以下内容重现您的问题,并且只有当DropDownStyle设置为Simple时才会发生。因此,如果可能的话,将DropDownStyle设置为DropDown。
注意我使用了5,000个项目并且没有闪烁,跳到10,000并且闪烁是有的,所以除了上面的建议之外,考虑如果可能的话,如果业务逻辑允许,可以减少ComboBox中的项目数。
使用测试并注意,当DropDownStyle设置为Simple时,即使SuspendLayout和ResumeLayout也无效。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
Dim ItemList As New List(Of item)
For x As Integer = 0 To 50000
ItemList.Add(New item With
{
.Exchange = "E" & x.ToString,
.PostCode = "P" & x.ToString
})
Next
ComboBox1.DisplayMember = "Exchange"
ComboBox1.DataSource = ItemList
End Sub
Private Sub RBExchange_CheckedChanged(sender As Object, e As EventArgs) _
Handles RBExchange.CheckedChanged, RBPostcode.CheckedChanged
Dim RB As RadioButton = CType(sender, RadioButton)
RB.SuspendLayout()
If RB.Name = "RBExchange" AndAlso RB.Checked Then
ComboBox1.DisplayMember = "Exchange"
ComboBox1.Text = ""
ElseIf RB.Name = "RBPostcode" AndAlso RB.Checked Then
ComboBox1.DisplayMember = "Postcode"
ComboBox1.Text = ""
End If
RB.ResumeLayout()
End Sub
End Class
Public Class item
Public Property Exchange
Public Property PostCode
End Class