Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
I am working on a C# windows application. I am facing a wierd problem in my code. I am using a dropdown to get some date. There are two events to change the value, one for ValueSelected and another for ValueChanged. Whenever I run that code while debugging, it show the correct date but when I run that code w/o debugging, it always shows wrong date. I also print the StackTrace in both mode. I found that codes call different methods in different mode. Here is the Code and Stack Trace:
Code :
C#
void cboPeriod_ValueSelected(object sender, PDIMultiColValueSelectEventArgs e)
{
    DataRow dr = cboPeriod.LookupGrid.CurrentRow;
    m_ThruDate = Convert.ToDateTime(libDataSetUtil.GetColValue(dr,       
           TC_Calendar_Detail.F_ENDINGDATE, m_NextPeriodBegDate.AddDays(-1) + M_ALL_DAY_LONG));
    m_FromDate = Convert.ToDateTime(libDataSetUtil.GetColValue(dr, TC_Calendar_Detail.F_BEGDATE, 
           m_CurPeriodBegDate));
            
    OnValueChanged();
}

void cboPeriod_ValueChanged(object sender, EventArgs e)
{
    DataRow dr = cboPeriod.LookupGrid.CurrentRow;

    m_ThruDate = Convert.ToDateTime(libDataSetUtil.GetColValue(dr, 
           TC_Calendar_Detail.F_ENDINGDATE, m_NextPeriodBegDate.AddDays(-1) + M_ALL_DAY_LONG));
    m_FromDate = Convert.ToDateTime(libDataSetUtil.GetColValue(dr, TC_Calendar_Detail.F_BEGDATE, 
           m_CurPeriodBegDate));
            
    OnValueChanged();
}

With Debugging :
C#
   at profdata.com.GeneralLedger.frmGLRPTTrialBalance.datPeriodDate_ValueChanged(Object sender, EventArgs e)
   at profdata.com.Controls.PDIDatePicker.OnValueChanged() in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDatePicker.cs:line 3804

  at profdata.com.Controls.PDIDatePicker.cboPeriod_ValueChanged(Object sender, EventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDatePicker.cs:line 3018
   at profdata.com.Controls.PDIMultiCol.OnValueChanged() in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 2415
   at profdata.com.Controls.PDIMultiCol.set_Value(String value) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 894
   at profdata.com.Controls.PDIMultiCol.SelectValue() in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 1753
   
   at profdata.com.Controls.PDIMultiCol.m_Grid_Click(Object sender, EventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 1351
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at profdata.com.Controls.PDIDataGrid.OnClick(EventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDataGrid.cs:line 5108
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)

Without Debugging :
C#
   at profdata.com.GeneralLedger.frmGLRPTTrialBalance.datPeriodDate_ValueChanged(Object sender, EventArgs e)
   at profdata.com.Controls.PDIDatePicker.OnValueChanged() in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDatePicker.cs:line 3804
   
   at profdata.com.Controls.PDIDatePicker.cboPeriod_ValueSelected(Object sender, PDIMultiColValueSelectEventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDatePicker.cs:line 3007
   at profdata.com.Controls.PDIMultiCol.OnValueSelected(PDIMultiColValueSelectEventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 1733
   at profdata.com.Controls.PDIMultiCol.SelectValue() in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 1756
   
   at profdata.com.Controls.PDIMultiCol.m_Grid_Click(Object sender, EventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIMultiCol.cs:line 1351
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at profdata.com.Controls.PDIDataGrid.OnClick(EventArgs e) in D:\PDI\Sandboxes\Ent_6.8.RU.Dev\Enterprise - WS\Lib\PDICtlSet1\ctlPDIDataGrid.cs:line 5108
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)


As you can see (the bold part in both stach trace), both stack traces are different. Without debugging, it is not calling the cboPeriod_ValueChanged event but calling cboPeriod_ValueSelected which should be called after ValueChanged or should not call. So do anyone have any idea that why this is happening.

My Understanding: If I am giving this code a break (like hitting a breakpoint, putting message box or let the thread sleep for sometime, it works fine)

Sorry for this long question. :(
Posted
Updated 8-Jan-14 20:33pm
v2
Comments
Sibasisjena 9-Jan-14 2:37am    
Both the methods are doing same thing right ?
astrovirgin 9-Jan-14 2:37am    
Yes, exactly same thing.
Naz_Firdouse 9-Jan-14 2:54am    
what is the need of using two events?
astrovirgin 9-Jan-14 2:57am    
I know that there is no need but this is how the code is written (actually it is some code already written in the framework and I can't modify it) but it is not the issue. Issue is why it is behaving different in different modes?
Fredrik Bornander 9-Jan-14 3:27am    
What does the method profdata.com.Controls.PDIMultiCol.SelectValue() look like?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900