By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,641 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,641 IT Pros & Developers. It's quick & easy.

Combobox bug

P: n/a
I've setup a custom combobox control that allows a multikey selections. This
lets the user enter key presses and the combo scrolls to the matching
selection. I run into a bug when the user opens the dropdown and enters a
new character which the box auto scrolls to. The combobox displays the
selected value but when I reference the text and selected value properties
they still have the old values. Has anyone seen a problem like this before,
or have any suggested work arounds?

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> I've setup a custom combobox control that allows a multikey selections.
This
lets the user enter key presses and the combo scrolls to the matching
selection. I run into a bug when the user opens the dropdown and enters a
new character which the box auto scrolls to. The combobox displays the
selected value but when I reference the text and selected value properties
they still have the old values. Has anyone seen a problem like this
before,
or have any suggested work arounds?

What had you than expect that it would display.
(In other words what are the old values, you cannot type in new values in)

I can think about something that you can maybe can mean with what you wrote,
however probably do you use an event to get those values or do you use a
button or even something else?

Cor
Nov 21 '05 #2

P: n/a
I've got a combo box (cboTown) with towns. For example 'New York', 'Orlando',
'San Diego'.
I've also got a button to display a message box with the cboTown.Text and
cboTown.SelectedValue. When I open the dropdown for the combo box and type
'S', the combo scrolls to 'San Diego'. When I open this a second time and
type 'N' the combo scrolls to 'New York'. I leave focus and the combo box is
displaying 'New York' when I click on the button it says the value of the
Text and SelectedValues are 'San Diego'. I'm confused since the combo is
displaying 'New York'. Any ideas?

"Cor Ligthert" wrote:
I've setup a custom combobox control that allows a multikey selections.
This
lets the user enter key presses and the combo scrolls to the matching
selection. I run into a bug when the user opens the dropdown and enters a
new character which the box auto scrolls to. The combobox displays the
selected value but when I reference the text and selected value properties
they still have the old values. Has anyone seen a problem like this
before,
or have any suggested work arounds?

What had you than expect that it would display.
(In other words what are the old values, you cannot type in new values in)

I can think about something that you can maybe can mean with what you wrote,
however probably do you use an event to get those values or do you use a
button or even something else?

Cor

Nov 21 '05 #3

P: n/a
Brian,

May I say it in otherwords, your selectedindex has another value than the
selectedvalue has?

This is than really strange,

While the combobox.textbox gives another string than is that textbox shows?

I knof this kind of behaviour from the selectionchangecommited, however you
did again not tell what events you are using for the combobox.

Cor
Nov 21 '05 #4

P: n/a
Here is my code for the combobox.

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class MultiKeyCombo
Inherits ComboBox

'Auto complete Combo variables
Private intSaveIndex As Integer

Private blnMultiKeySelect As Boolean = False

Public Property MultiKeySelect() As Boolean
Get
Return blnMultiKeySelect
End Get
Set(ByVal Value As Boolean)
blnMultiKeySelect = Value
End Set
End Property
Private Sub MultiKeyCombo_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp

If MultiKeySelect Then
'AutoComplete(CType(sender, ComboBox), e)
Dim cbo As ComboBox = DirectCast(Me, ComboBox)
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete,
Keys.Down, Keys.Tab, Keys.Shift, Keys.LShiftKey, Keys.RShiftKey, Keys.ShiftKey
Return
End Select
Dim ComboBoxText As String = cbo.Text

Dim FirstFound As Integer = cbo.FindString(ComboBoxText)

If FirstFound >= 0 Then
Dim FirstFoundItem As Object = cbo.Items(FirstFound)
Dim FirstFoundText As String = cbo.GetItemText(FirstFoundItem)
cbo.Text = FirstFoundText
cbo.SelectionStart = ComboBoxText.Length
cbo.SelectionLength = cbo.Text.Length

'Save the last index
intSaveIndex = FirstFound
Else
'If no match is found go back to the last index and select the
'whole text
If blnMultiKeySelect = True Then
'cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1)

If intSaveIndex > 0 Then
cbo.SelectedIndex = intSaveIndex
End If
cbo.SelectionStart = 0
cbo.SelectionLength = cbo.Text.Length()
End If
End If
End If

End Sub

Private Sub MultiKeyCombo_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave

If MultiKeySelect Then

If MyBase.Text <> "" Then
'Check to make sure an invalid entry is not left in the
combobox
Dim cbo As ComboBox = DirectCast(sender, ComboBox)
Dim ComboBoxText As String = cbo.Text
Dim FirstFound As Integer = cbo.FindStringExact(ComboBoxText)
If FirstFound < 0 Then
cbo.SelectedIndex = intSaveIndex
Else
cbo.SelectedIndex = FirstFound
End If
End If
End If

End Sub
End Class

"Cor Ligthert" wrote:
Brian,

May I say it in otherwords, your selectedindex has another value than the
selectedvalue has?

This is than really strange,

While the combobox.textbox gives another string than is that textbox shows?

I knof this kind of behaviour from the selectionchangecommited, however you
did again not tell what events you are using for the combobox.

Cor

Nov 21 '05 #5

P: n/a
Brian,

I have tried your code.

Private Sub Form12_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("text")
dt.Columns.Add("value")
dt.LoadDataRow(New Object() {"Brian", "1"}, True)
dt.LoadDataRow(New Object() {"Cor", "2"}, True)
dt.LoadDataRow(New Object() {"Armin", "3"}, True)
dt.LoadDataRow(New Object() {"Terry", "4"}, True)
MultiKeyCombo1.DataSource = dt
MultiKeyCombo1.DisplayMember = "text"
MultiKeyCombo1.ValueMember = "value"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Me.MultiKeyCombo1.SelectedValue.To String)
End Sub

When Armin is selected it shows 3 and when I select after that Cor it shows
2

However when I understand what you are after there are better
implementations of this. This one I made once for Bernie, however there are
much more on internet Bernie had a special problem.

http://groups-beta.google.com/group/...71d7cb3c?hl=en

At the end of the thread he tells it works.

Cor


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.