The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Keyboard input of numeric values and commas as decimal separator
One of the questions I frequently get is how to get the same behavior as Excel when entering numeric values. With the same behavior I mean that Excel detects the current users locale setting for decimal separator and makes the decimal point on the numeric keyboard input the correct character. This is only done for the numeric keypad, the point and comma on regular part of the keyboard remain unchanged. Doing so is very easy but finding the right place is not completely obvious as in most events the KeyEventArgs or Message parameters cannot be changed or changing them has no effect.   The proper place to do this is the PreProcessMessage() function of a control. The code below does just that, just subclass the a TextBox control and override the PreProcessMessage() function and you are done.
 
 
PublicOverridesFunction PreProcessMessage(ByRef msg As System.Windows.Forms.Message) AsBoolean
   If msg.Msg = &H102 Then
      If msg.WParam.Equals(New IntPtr(&H2E)) _
         AndAlso msg.LParam.Equals(New IntPtr(&H530001)) Then
         ' Point in the numeric keypad pressed
         If Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ","Then
            ' And the decimal separator is a ',' for the current settings
            ' Change the message to enter a comma instead of a poin
            msg.WParam = New IntPtr(&H2C)
            msg.LParam = New IntPtr(&H330001)
         EndIf
      EndIf
  EndIf

  ' Do the default actions
   ReturnMyBase.PreProcessMessage(msg)
EndFunction
 
Now if you are using a DataGridView things are a little more complicated :-(. The code is a little long for this blog post but I did put it up on my web site. Take a look at this FAQ entry if you are interested.
 
Maurice de Beijer
Published Fri, Sep 15 2006 9:20 by Maurice
Filed under:

Comments

# All about tadalafil online@ Saturday, July 12, 2008 12:32 AM

Order zithromax seek azithromycin Where can I buy azithromycin get zithromax online without prescrption?

# All about tadalis@ Saturday, July 12, 2008 1:24 AM

Buying zithromax find azithromycin Where can I purchase azithromycin aquire zithromax online without prescrption?

# All about buy tadalafil@ Tuesday, July 15, 2008 11:27 PM

Buy zithromax order azithromycin Where can I buy azithromycin buy zithromax online without prescrption?

# femara side effects@ Sunday, October 19, 2008 7:43 AM

femara side effects

by Veictavesseds

# You must see it !!!@ Sunday, October 19, 2008 11:32 AM

Did you see it ? :) It's simply beautyfull thing <u>http://adventures.110mb.com</u>

by sharpbobby

# Earnings@ Tuesday, October 21, 2008 12:13 PM

Dear members of a forum. Yesterday I have seen an interesting site. On it site is good offer on earnings on the Internet.

Is it really what owners of this site offer?

Adress of the site is <b>http://takegold.110mb.com</b>

by sweetnettie

# All greetings!@ Monday, December 01, 2008 12:13 PM

I am here at a forum newcomer. Until I read and deal with the forum.

Let's learn!

by Appearoamibia

# new easymeds site@ Thursday, February 05, 2009 1:13 PM

http://easymeds.com.ua/ | easymeds

# new easymeds site@ Friday, February 06, 2009 12:07 PM

http://easymeds.com.ua/ | easymeds

# http://blogproautos.com@ Thursday, April 09, 2009 9:28 AM

Questions and answers about Body row weight and Extreme weight loss pill here http://blogprohealth.com !

Tired of searching for Order? This way http://blogprorealestate.com !

# I Lost 30 Pounds in 30 Days@ Tuesday, April 28, 2009 9:01 PM

Great post! Just wanted to let you know you have a new subscriber- me!