473,387 Members | 1,431 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,387 software developers and data experts.

How to limit data entry to numbers only in combobox

I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch
Nov 21 '05 #1
10 9075
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing 'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com...
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #2
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing 'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com...
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #3
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing 'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com.. .
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch


Nov 21 '05 #4
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing 'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com.. .
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch


Nov 21 '05 #5
Tosch,

Tosch,

Some hours ago I showed this sample too EDB he told me that it was what he
wanted, however, that it can be optimized, and he is right, it where first
two samples.

http://groups.google.com/groups?selm...TNGP12.phx.gbl

I did not change them yet.

I hope however that it helps you as well.

Cor

"Tosch" <to**********@swissonline.ch>
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing
'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com. ..
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #6
Tosch,

Tosch,

Some hours ago I showed this sample too EDB he told me that it was what he
wanted, however, that it can be optimized, and he is right, it where first
two samples.

http://groups.google.com/groups?selm...TNGP12.phx.gbl

I did not change them yet.

I hope however that it helps you as well.

Cor

"Tosch" <to**********@swissonline.ch>
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing
'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com. ..
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #7
"Tosch" <to**********@swissonline.ch> schrieb:
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.


IIRC that's caused by the buggy implementation of the combobox.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #8
"Tosch" <to**********@swissonline.ch> schrieb:
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.


IIRC that's caused by the buggy implementation of the combobox.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #9
Hi Tosch,

I tried your code inside vs 2003, which is all that I work with, and it
worked fine. So the answer has to be that there's a bug in 2002. Also, you
have to add a few characters - backspace, delete, arrow keys, etc. So you
may want to modify your code, into something like this:

Dim KeyAscii As Integer = Asc(e.KeyChar)
Select Case KeyAscii

Case 8, 27, 48 To 57, 9

Case Else

KeyAscii = 0

End Select

If KeyAscii = 0 Then

e.Handled = True

Else

e.Handled = False

End If
HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:8r********************************@4ax.com...
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing
'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com. ..
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #10
Hi Tosch,

I tried your code inside vs 2003, which is all that I work with, and it
worked fine. So the answer has to be that there's a bug in 2002. Also, you
have to add a few characters - backspace, delete, arrow keys, etc. So you
may want to modify your code, into something like this:

Dim KeyAscii As Integer = Asc(e.KeyChar)
Select Case KeyAscii

Case 8, 27, 48 To 57, 9

Case Else

KeyAscii = 0

End Select

If KeyAscii = 0 Then

e.Handled = True

Else

e.Handled = False

End If
HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:8r********************************@4ax.com...
This is my code and it's not working. I want only numbers 0-9
accepted:

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
Select Case e.KeyChar
Case "0" To "9"
Case Else
e.Handled = True
End Select
End Sub

BTW: I'm using VS2002.

Tosch
On Thu, 11 Nov 2004 09:58:23 -0500, "Bernie Yaeger"
<be*****@cherwellinc.com> wrote:
Hi Tosch,

Use the keypress event. The following worked fine for me, disallowing
'a':
If e.KeyChar = "a" Then

e.Handled = True

End If

HTH,

Bernie Yaeger

"Tosch" <to**********@swissonline.ch> wrote in message
news:18********************************@4ax.com. ..
I have a combobox where a user can select a zoom factor or enter a
zoom factor.
I tried to limit entry into the combobox to numbers only by catching
the keydown event and setting e.handled = true if any non number
characters are entered.
But those characters still appear in the combobox. Is this a combobox
bug?
If yes any workarounds?

Tosch

Nov 21 '05 #11

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

Similar topics

2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
5
by: Nancy | last post by:
I have two tables: TblCourse CourseID CourseName TblClass ClassID CourseID ClassDate
1
by: Trent | last post by:
I am in the design phase of a new database and am having a devil of a time with a subform. I have three tables that relate to problem - Suppliers tbl, Customers tbl and a SuppliersCustomers tbl....
0
by: Tosch | last post by:
I have a combobox where a user can select a zoom factor or enter a zoom factor. I tried to limit entry into the combobox to numbers only by catching the keydown event and setting e.handled = true...
4
by: Melson | last post by:
Hi I've a problem. Can anyone help. I would like to use datagrid for data entry. How can I set the number of rows in the datagrid. And use the datagrid to update the ms sql table. regards...
1
by: Caro | last post by:
Hello, Is it possible to create a sort of validation rule that will limit the data entry in a field to even numbers only ? thaks, Caro
1
by: tizmagik | last post by:
I have a combobox on a continuous form that has a recordsource that is set upon Form_Load event via VBA (based on initial form data and external form data entered). For data entry purposes the...
3
by: nt8jbwu02 | last post by:
I would like to allow a user to enter an ip address (quad octet format: www.xxx.yyy.zzz) in a combo box and then add it to the list when they have completed the entry. How can I do this? The...
1
by: injanib via AccessMonster.com | last post by:
is it possible that if the limit to list property of a combobox is set to true the focus is passed onto another field? What I mean is that I have a combo box with the limit to list property set to...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.