473,769 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combobox bug

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
5 1842
> 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
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.Selecte dValue. 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
Brian,

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

This is than really strange,

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

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

Cor
Nov 21 '05 #4
Here is my code for the combobox.

Option Strict Off
Option Explicit On

Imports Microsoft.Visua lBasic
Imports System
Imports System.Drawing
Imports System.Windows. Forms

Public Class MultiKeyCombo
Inherits ComboBox

'Auto complete Combo variables
Private intSaveIndex As Integer

Private blnMultiKeySele ct As Boolean = False

Public Property MultiKeySelect( ) As Boolean
Get
Return blnMultiKeySele ct
End Get
Set(ByVal Value As Boolean)
blnMultiKeySele ct = Value
End Set
End Property
Private Sub MultiKeyCombo_K eyUp(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyUp

If MultiKeySelect Then
'AutoComplete(C Type(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(First Found)
Dim FirstFoundText As String = cbo.GetItemText (FirstFoundItem )
cbo.Text = FirstFoundText
cbo.SelectionSt art = ComboBoxText.Le ngth
cbo.SelectionLe ngth = 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 blnMultiKeySele ct = True Then
'cbo.Text = cbo.Text.Substr ing(0, cbo.Text.Length - 1)

If intSaveIndex > 0 Then
cbo.SelectedInd ex = intSaveIndex
End If
cbo.SelectionSt art = 0
cbo.SelectionLe ngth = cbo.Text.Length ()
End If
End If
End If

End Sub

Private Sub MultiKeyCombo_L eave(ByVal sender As Object, ByVal e As
System.EventArg s) 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(send er, ComboBox)
Dim ComboBoxText As String = cbo.Text
Dim FirstFound As Integer = cbo.FindStringE xact(ComboBoxTe xt)
If FirstFound < 0 Then
cbo.SelectedInd ex = intSaveIndex
Else
cbo.SelectedInd ex = 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.textbo x gives another string than is that textbox shows?

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

Cor

Nov 21 '05 #5
Brian,

I have tried your code.

Private Sub Form12_Load(ByV al sender As System.Object, _
ByVal e As System.EventArg s) 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(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
MessageBox.Show (Me.MultiKeyCom bo1.SelectedVal ue.ToString)
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2799
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
7
8528
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
8
12105
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
1
2497
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new DataTable("table"); testTable.Columns.Add("Col1", typeof(Int32)); testTable.Columns.Add("Col2", typeof(String)); testTable.Rows.Add(testTable.NewRow());
3
6834
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article: http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx I have a problem when there are two DataGrid's on one form, and when I switch focus from one grid to the other. To be more precise, when I'm editing a combo box column in one grid, and then click in the combo column of...
2
6204
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following criteria that I wanted to meet, but nothing did: - No reliance on a separate library - No unmanaged code - Easy subclassing of System.Windows.Forms.Combobox (i.e. no custom control monstrosity) - No extra funky features that I didn't need
4
4620
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
6
2883
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
1
3373
by: polocar | last post by:
Ciao a tutti, leggendo qua e là per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non è possibile impostare la sua altezza ad un valore diverso da 21. Forse, cambiando la dimensione del font, si potrebbe riuscire a cambiare anche l'impostazione dell'altezza... (MS farebbe comunque meglio ad introdurre per il ComboBox una proprietà AutoSize impostabile a "false"...
5
5916
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.