Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to subtract my DateTime column in my DataGrid from the systems current time and then if total minutes are less or equal to 60 minutes I need a MessageBox to show.

What I have tried:

C#
           DateTime end = (DateTime)value;
           DateTime curtime = DateTime.Now;

           TimeSpan span = end - curtime;
           double totalMinutes = span.TotalMinutes;

           if (totalMinutes <= 60)
           {

            MessageBoxResult result = MessageBox.Show("Need Attention", "Confirmation");
return true;
           }
           else
           {
               return false;
           }
Posted
Updated 19-Dec-19 5:54am
v4

The Show for mesagge box is never executed because it's after the return statement. Try changing the order of the lines
if (totalMinutes <= 60)
{
    MessageBoxResult result = MessageBox.Show("Need Attention", "Confirmation");
    return true;
}

Also note that if this code is from inside a property, it's probably a good idea to rethink the design so that you won't show message box inside a property getter.
 
Share this answer
 
v2
Comments
Member 12876243 19-Dec-19 11:45am    
Thanks I will correct it.. My Message box seems to display for every Time Column even if it is greater than 60 Minutes unsure on what is happening.
Wendelius 19-Dec-19 11:58am    
Is this code inside a property? If it is, that's probably causing the situation, since every time the value of the property is fetched, the message box is shown.
Member 12876243 19-Dec-19 12:24pm    
Code is inside a IValueConverter
Wendelius 19-Dec-19 12:46pm    
This would probably cause the same effect, each time the value is converted (=queried) the message box is hit.
Quote:
My Message box seems to display for every Time Column even if it is greater than 60 Minutes unsure on what is happening.

So use the debugger and see exactly what is in value, curtime, span, and totalMinutes - that should start to tell you what is happening, and that should give you why.

But without your code running and feeding values to your property / method everything is just guesswork. The debugger can tell you whattah values are, and that's what you need.
 
Share this answer
 

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