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

Replacing chars when typing

Hi!

I want when user type comma in textbox to
automaticly replace in dot.

In keypress event i have something like this:

if (e.KeyChar == 44)
{
textBox1.Text = textBox1.Text.Replace(",",".");
}

but it doesn't work in way that i want. Is there any
way to do that?

Thnx.
Nov 18 '08 #1
6 5383
On Tue, 18 Nov 2008 15:45:36 -0800, Trooper <tr*@nema.emailwrote:
Hi!

I want when user type comma in textbox to
automaticly replace in dot.

In keypress event i have something like this:

if (e.KeyChar == 44)
{
textBox1.Text = textBox1.Text.Replace(",",".");
}

but it doesn't work in way that i want. Is there any
way to do that?
Just change the KeyChar property in your event handler. When it's equal
to ',', set it to '.' (and use the character literals, not ASCII codes).

Pete
Nov 19 '08 #2
DH
Trooper wrote:
Hi!

I want when user type comma in textbox to
automaticly replace in dot.

In keypress event i have something like this:

if (e.KeyChar == 44)
{
textBox1.Text = textBox1.Text.Replace(",",".");
}

but it doesn't work in way that i want. Is there any
way to do that?

Thnx.
I would do it in the TextChanged event handler and just
textBox1.Text=textBox1.Text.Replace(',','.');

that is assuming it is ok for it to replace all the ',' with '.' once
the user has finished entering what ever they are entering.

what exactly do you mean by it doesn't work the way you want it to?
What do you expect and what does it do?
Nov 19 '08 #3
Peter Duniho wrote:
>
Just change the KeyChar property in your event handler. When it's equal
to ',', set it to '.' (and use the character literals, not ASCII codes).

Pete

Did you mean to put e.KeyChar = Keys.Decimal; ??
KeyChar property is read-only and i can't assign anything.
Nov 19 '08 #4
On Tue, 18 Nov 2008 16:02:48 -0800, Trooper <tr*@nema.emailwrote:
Peter Duniho wrote:
> Just change the KeyChar property in your event handler. When it's
equal to ',', set it to '.' (and use the character literals, not ASCII
codes).
Pete


Did you mean to put e.KeyChar = Keys.Decimal; ??
KeyChar property is read-only and i can't assign anything.
If KeyChar is read-only, then you are not actually handling the KeyPress
event as your original post claimed.

http://msdn.microsoft.com/en-us/libr...s.keychar.aspx
Nov 19 '08 #5
DH wrote:
I would do it in the TextChanged event handler and just
textBox1.Text=textBox1.Text.Replace(',','.');
This works fine, but it moves cursor at begining of textbox.
that is assuming it is ok for it to replace all the ',' with '.' once
the user has finished entering what ever they are entering.

what exactly do you mean by it doesn't work the way you want it to?
What do you expect and what does it do?
All I want to do is when user type ',' it automaticly change to '.'
I want to intercept ',' and replace it with '.'
Nov 19 '08 #6
Trooper skrev:
DH wrote:
>I would do it in the TextChanged event handler and just
textBox1.Text=textBox1.Text.Replace(',','.');

This works fine, but it moves cursor at begining of textbox.
That's because you replace textBox1.Text with a new value (the only
thing you are allowed to)

Store the cursor position before modifying the text, and then restore it.

--
Bjørn Brox
Nov 19 '08 #7

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

Similar topics

2
by: Steve | last post by:
Hi; I am trying to write a rountine ( below ) that will go into a colum of text data type ( fae.pmcommnt ) locate the word "to" and replace it. I have the routine below. I get no error...
3
by: dornick | last post by:
So I want to do the above, and I really, REALLY don't want to rewrite the entire file. I've been working on it for a while now, and can't for the life of me get it functioning. Basically, I want...
3
by: MLH | last post by:
I'm trying to type (a), (b) or (c) into an Access 97 memo field. Access keeps turning it into a copyright symbol ( © ) How can I override that? I don't want a copyright symbol.
3
by: Ivan | last post by:
Hi, how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox? Thanks, Iavmn
2
by: Sebastian Araya | last post by:
Hello, I'm using php-5.0.5-pl3; I've created a collector class which populates itself with DOM's nodes from every object which needs to output data. So, at the end of the process, the...
1
by: riscy | last post by:
I'm having odd behaviour of VS 2003 pro recently. It happen when Dell 9200 returned from repairs with new motherboard to fix audio out socket problem (as they say). I installed Visual Assist X and...
2
by: ngrover | last post by:
When accessing strings from a french language utf-8 .txt file (that has been resgen'ed into a .resources file) via ResourceManager.GetString() method, I am encountering a problem. All the special...
4
by: olseni | last post by:
Hi all I have a problem using datasheet in a subform (Access 2007). When the user is updating numbers or text in a column, and jumps to the next record using the 'Enter' button, sometimes, but...
3
by: Simon van Beek | last post by:
Dear reader, What can be wrong in my ComboBox, the property "Auto Expand" is set to Yes, but by typing in the ComboBox it doesn't expand. Is this because the source of the ComboBox is a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.