English 中文(简体)
日期 价值不变 活动月复一日
原标题:DateTimePicker ValueChanged Event repeats with month arrow
  • 时间:2011-03-28 12:31:35
  •  标签:
  • c#

When the month forward or backward arrow is clicked on my DateTimePicker control it repeatedly fires the ValueChanged event. I have to use the debugger to stop the application.

注:只要我点点点一个日期,我的申请就可进行罚款。

The MSDN documentation shows examples for creating the control. But I cannot find any example function called dateTimePicker1_ValueChanged(). The skeleton for this function was created for me, when I double clicked on the control in the VS.NET2008 designer.

最佳回答

Dave81 set me on to the right track. If you do what he says, the problem is, that when the user changes the value manually, the CloseUp event obviously isn t triggered. The way I ve fixed this problem with the constant re-firing of the month change event, is to change my ValueChanged event to only refresh if the calendar isn t dropped down. I.e.:

private bool _calendarDroppedDown = false;
//called when calendar drops down
private void dateStartDateTimePicker_DropDown(object sender, EventArgs e)
{
  _calendarDroppedDown = true;
}
//called when calendar closes
private void dateStartDateTimePicker_CloseUp(object sender, EventArgs e)
{
  _calendarDroppedDown = false;
  RefreshToolbox(null, null); //NOW we want to refresh display
}

//This method is called when ValueChanged is fired
public void RefreshToolbox(object sender, EventArgs e)
{ 
  if(_calendarDroppedDown) //only refresh the display once user has chosen a date from the calendar, not while they re paging through the days.
    return;
  ...
}
问题回答

我不清楚你想要达到什么目标,但我的猜测是,例如,你想要展示一个信息箱或类似的东西。 如果是这样的话,就不会有担心,因为你正面临同样的问题,我很想在一段时间前会问。 www.un.org/Depts/DGACM/index_french.htm - event, use the CloseUp -event.CloseUp - 只有在用户最终选择某种价值时,才会启动发明。 希望是你们所期待的。 如果希望更新,例如向用户显示的某些计算方法,你将使用ValueChanged<>。 - 发明。

When you click on the down arrow of a datetimepicker, it displays a default date. When you click on any date in the datetime picker, it fires the datetimepicker1_valuechanged event. Whatever you have put the skeleton for the event, works fine then. Unnikrishnan C





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签