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

double trip through an event

I have a DateTimePicker. The user should pick the first of the month. If he
doesn't, the ValueChanged event pops a messagebox and changes the value to
the first. Problem is that changing the Value in the event triggers the event
twice, and the messagebox appears twice, though I don't see why it should.
Any explanation?

private void dtpRenew_ValueChanged(object sender, System.EventArgs e)
{
int day = dtpRenew.Value.Day ;
if(day != 1)
{ MessageBox.Show("Starting Date must be first day of the month!") ;
dtpRenew.Value = dtpRenew.Value.AddDays(1-day) ;
}
}
Nov 17 '05 #1
2 985
On Fri, 1 Apr 2005 13:37:05 -0800, "eye5600"
<ey*****@discussions.microsoft.com> wrote:
I have a DateTimePicker. The user should pick the first of the month. If he
doesn't, the ValueChanged event pops a messagebox and changes the value to
the first. Problem is that changing the Value in the event triggers the event
twice, and the messagebox appears twice, though I don't see why it should.
Any explanation?

private void dtpRenew_ValueChanged(object sender, System.EventArgs e)
{
int day = dtpRenew.Value.Day ;
if(day != 1)
{ MessageBox.Show("Starting Date must be first day of the month!") ;
dtpRenew.Value = dtpRenew.Value.AddDays(1-day) ;
}
}


Use BeginInvoke:

private void dateTimePicker1_ValueChanged(object sender,
System.EventArgs e)
{
int day = dateTimePicker1.Value.Day;
if (day != 1)
{
this.BeginInvoke(new
MethodInvoker(ValidateDate));
}
}
private void ValidateDate()
{
int day = dateTimePicker1.Value.Day;
dateTimePicker1.Value =
dateTimePicker1.Value.AddDays(1-day);
MessageBox.Show("Starting Date must be first
day of the month!") ;
}
--
Ludwig Stuyck
http://www.coders-lab.net
Nov 17 '05 #2
Thanks. Creating a new object also works, and is a bit more compact. I don't
understand why this happens, especially as the example is essentially the
same as an example.

private void dtpRenew_ValueChanged(object sender, System.EventArgs e)
{
DateTime dt = dtpRenew.Value ;
if (dt.Day != 1)
{
MessageBox.Show("Date must be first day of the month!");
dtpRenew = new DateTimePicker() ;
dtpRenew.Value = dt.AddDays(1-dt.Day) ;}
}

Nov 17 '05 #3

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

Similar topics

2
by: Pascal | last post by:
Why does this not work, and how should i do this convert in stead: string x = double.MinValue.ToString(); double y = Convert.ToDouble(x); i get this exception: An unhandled exception of type...
3
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
1
by: Don Parker | last post by:
I want to have 2 dropdowns - one containing categories of items such as Furniture, Applicances etc. The other dropdown is a list of subcategories that match the first drop down. So if the user...
60
by: Erick-> | last post by:
hi all... I've readed some lines about the difference between float and double data types... but, in the real world, which is the best? when should we use float or double?? thanks Erick
7
by: Tony Girgenti | last post by:
Hello. I'm trying to undetrstand ASP.NET 2.0 and javascript. When i have a button and i click on it and i see the web broswer progress bar at the bottom do something, does that mean that there...
3
by: moondaddy | last post by:
I have an htm page that will be passing data to the server via parameters in a hidden iframe's aspx page. I not need the aspx page to return back to the htm page because the mission has already...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
2
by: Markus Dehmann | last post by:
I have two integers i1 and i2, the second of which is guaranteed to be between 0 and 99, and I encode them into one double: double encoded = (double)i1 + (double)i2 / (double)100; So, for...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.