BUG: Setting ComboBox Control Text in Click Event Wipes Out TextID: Q168824
|
When setting the ComboBox control Text property in the Click event of ComboBox control, the text always returns blank. This is different behavior than Visual Basic 3.0 and Visual Basic 4.0.
Instead of setting the Text property of the ComboBox control in the Click
event, do it at the LostFocus event by shifting the focus to another
control, such as TextBox, although it will leave the focus set to the
TextBox. To work around that, hide a TextBox behind the ComboBox with
TabStop property set to False; in the GotFocus event of the Textbox, set
the focus back to the ComboBox. To place a TextBox behind the ComboBox in
design time, choose the Send To Back menu command from the Format/Order
menu; in runtime, set the z-order of TextBox to 1.
The following code example shows how to keep the text of ComboBox control
after being set at the Click event:
Dim ClickFlag As Integer
Private Sub Combo1_Click()
ClickFlag = True
Text1.SetFocus
End Sub
Private Sub Combo1_LostFocus()
If ClickFlag = True Then
Combo1.Text = Mid(Combo1.Text, 4)
ClickFlag = False
End If
End Sub
Private Sub Form_Load()
ClickFlag = False
With Combo1
.AddItem "1. Adam"
.AddItem "2. Bob"
.AddItem "3. Charles"
End With
Combo1.Text = Mid(Combo1.List(0), 4)
'Hide Text1 under Combo1
Text1.Move Combo1.Left, Combo1.Top, Combo1.Width, Combo1.Height
Text1.ZOrder (1)
Text1.TabStop = False
End Sub
Private Sub Text1_GotFocus()
Combo1.SetFocus
End Sub
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
Private Sub Combo1_Click()
Combo1.Text = Mid(Combo1.Text, 1, 3)
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "1. Adam"
.AddItem "2. Bob"
.AddItem "3. Charles"
End With
Combo1.Text = Mid(Combo1.List(0), 4)
End Sub
Additional query words: kbVBp500bug kbVBp600bug kbdse kbDSupport kbVBp kbCtrl
Keywords :
Version :
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: June 16, 1999