473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with Combobox Autofill Code

Hi,
I have some comboboxes that are created dynamically at run time based
on user actions. I found a procedure on a message board to autofill
the combobox text from the dataview that the comboboxes are bound to.
It works perfectly on the comboboxes that I have created at design
time, but the ones that I create runtime behave differently.

The problem is that when the user tabs onto the combobox, the box
stays blank, which is fine. However, once they press any key, the
first value in the bound dataview appears in the box and the key that
they pressed appears at the end of this text. For example, let's say
that the first value in the bound dataview is the string "example".
If the user hits the letter "a", the box immediately displays
"examplea", which forces the user to backspace all the way to clear
out this unwanted value and then begin typing their string again. At
that point, everything autofills fine, but it's obviously
unaccepatable to force every entry to begin with hitting a key and
then backspacing.

The combobox is created with this code:

Dim newCbo As New ComboBox
With newCbo
.Name = "cboUOM" & intCount + 1
.DataSource = vueUOM
.DisplayMember = "USUOM"
End With
AddHandler newCbo.Validating, AddressOf ValNewCbo
AddHandler newCbo.KeyPress, AddressOf FillUOMCbo
AddHandler newCbo.LostFocus, AddressOf ActiveIngrRow
AddHandler newCbo.GotFocus, AddressOf ActiveIngrRow
Controls.Add(newCbo)
The dataview looks like this and is part of the form load procedure:
Dim vueUOM As New DataView
vueUOM.Table = ds.UOMConv
vueUOM.Sort = "USUOM"
The handler that takes care of the autofill function is this:

Private Sub FillUOMCbo(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)
Dim APIRetVal As Integer
Dim sText As String
Dim thisCbo As ComboBox = DirectCast(sender, ComboBox)
With thisCbo
If Not (e.KeyChar = Convert.ToChar(Keys.Back) Or e.KeyChar
= Convert.ToChar(Keys.Escape) Or e.KeyChar =
Convert.ToChar(Keys.Enter)) Then
If .SelectionLength 0 Then
sText = .Text.Substring(0, .SelectionStart) &
e.KeyChar
Else
sText = .Text & e.KeyChar
End If
APIRetVal = SendMessage(.Handle, CB_SELECTSTRING, -1,
sText)
If APIRetVal <-1 Then
.SelectionStart = sText.Length
.SelectionLength = .Text.Length - .SelectionStart
+ 1
Else
.Text = sText
.SelectionStart = sText.Length + 1
End If
e.Handled = True
End If
End With
End Sub

Also note that this is declared in the class declarations:

Public Const CB_SELECTSTRING = &H14D
' API Declarations
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal
wParam As Integer, ByVal lParam As String) As Integer
Can anybody see why the autofill is behaving in the manner that it
is? I just don't see what I need to do to make it work as intended.

Thanks,
Randy

Jun 29 '07 #1
0 2033

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Sharman | last post by:
I'd like to design my pages to work cooperatively with browser autofill features. I've loked around, but can't find any good documentation on supported/unsupported field names...
1
by: shortbackandsides.no | last post by:
I'm having a lot of difficulty trying to persuade the Google toolbar autofill to act consistently, for example ======================= <html><head> <title>autofill test</title> </head><body>...
1
by: Nick J | last post by:
Hi, I remember at one point access would autofill a text box when filtering by form, Like for example as I would type it would come up with matching records, similar to AutoComplete in Internet...
2
by: DBQueen | last post by:
Hi - In my A2K database, I have a form with 2 Unbound Comboboxes, both of which open up forms to a particular record. One of these comboboxes works perfectly. For some reason the 2nd one WILL...
6
by: Andi Plotsky | last post by:
Hi - I sent this request last week, but didn't get an answer to my problem - let's try again: In my A2K database, I have a form with 2 Unbound Comboboxes, both of which open up forms to a...
2
by: Andre Ranieri | last post by:
I'm retouching our corporate web site that, among other things, allows customers to log in and pay their invoices online. I noticed that on the checkout page, the credit card number textbox...
4
by: HTS | last post by:
I have written a membership database application (PHP + mySQL) and need to prevent autofill from filling in fields in a member record edit form. I know I can turn off autoFill in my browsers, I...
1
by: Rissoman | last post by:
Hello, I have an issue were I have a zipcode textbox in an atlas ajax updatepanel. When you tab out of the zip textbox and the shipping is calculated. I know this works perfect! Then a user...
3
by: gsherp | last post by:
I have onchange in my javascript and there is no bug in the code. However, whenever a user uses the autofill feature in the browser, none of my javascript events are ever fired. This causes none of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.