Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have made a calendar, now I want user to choose the days. For example there is a calendar of month May. User wants to see all the dates for Monday column (e.g. Mondays of the month : 5,12,19,26) <-- as Monday falls in these days of the month. Users is allowed to chose by using Switch statement and case from 0 to 6.
My question is how can I retrieve the days from a column that user chose and display it like in the example (e.g. Mondays of the month : 5,12,19,26). I don't want an answer in code. I just want somebody to give me an idea on how can I do this or hints in code with explanation, not straight forward answer.
I use 2d array to make calendar table. 2d array contains columns and rows that are required by me. I am also using single array to hold string of days that act as a column for they days that 2d array holds. (E.g May
Mon Tues...
1 2...)
Thanks.
I think the best way is to handle the click of the user. After that you can just add/substract 7 (number of days in a weel) to the day he chooses. Then make sure to not exceed (>31 or <1) the number of days in a month.
private void dateTimeInput1_ValueChanged(object sender, EventArgs e)
{
DateTime selectedDate = dateTimeInput1.Value;
DateTime theNextWeek = selectedDate.AddDays(+7);
DateTime thePreviousWeek = selectedDate.AddDays(-7);
}
All you have to do is select all the weeks.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a list of items with the following pattern of results in a variable named dataList
{PH:8,PDate:3/22/2021,
PH:8,PDate:3/23/2021,
PH:4,PDate:3/24/2021,
PH:8,PDate:3/29/2021,
PH:8,PDate:3/30/2021,
PH:4,PDate:3/31/2021,
PH:8,PDate:4/5/2021,
PH:8,PDate:4/6/2021}
The list may have more items like this and I just put a few to understand the pattern. And the list has a type which can hold an <int,DateTime> object.
The week of the day starts on Monday. So from the above list the first 3 items belongs to the same week. Second 3 items belongs to another week and the last 2 items belongs to a different week.
I want to filter this like below
{PH:20,PDate:3/22/2021,
PH:20,PDate:3/29/2021,
PH:16,PDate:4/05/2021}
which is like the sum of PH for each week. Any helps appreciated Thanks.
given you don't really have any code, you want to do something like the following where we group by week number starting on monday, then select the first items date and sum all the ints. Then when printing out we need to adjust the first items date to be the start of the week by subtracting off the first day of week.
var list = new List<(int, DateTime)>();
list.Add((8, new DateTime(2021,3,22)));
list.Add((8, new DateTime(2021,3,22)));
list.Add((4, new DateTime(2021,3,24)));
var r = list.GroupBy(l =>
CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(l.Item2, CalendarWeekRule.FirstFullWeek,
DayOfWeek.Monday))
.Select(g => (g.Sum(x => x.Item1), g.First().Item2))
.ToList();
r.ForEach(i => Console.WriteLine($"{i.Item1} {i.Item2 - new TimeSpan(i.Item2.DayOfWeek - DayOfWeek.Monday, 0,0,0)}"));
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a DateTimePicker and two buttons on a form. The buttons are intended to allow a user to cycle backwards and forwards through the dates displayed in the picker.
The code DateTimePicker.Value.AddDays(1); increments the value displayed and DateTimePicker.Value.AddDays(-1); decrements it. It seems a bit clunky to me but this works as expected, is passing in a value of -1 the correct way to decrement the displayed date?
Why isn't there a SubtractDays() method?
As you've seen, you can use AddDays with a negative amount to subtract days, so there's no need for the extra methods (there would need to be one for each of the Add methods). If it really bothers you, you can write extension Subtract methods for all the Add methods.
For example
public static class DateTimeExtensions
{
public static DateTime SubtractDays(this DateTime start, int days)
{
return start.AddDays(-days);
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a DataGridView with 6 columns; I want the first column to display the days of the week. And the second column should display a schedule per day. But I want them to display in vertical order, not in horizontal way. But I can't figure out how to do it.
I have it like this:
And I want it like this:
according to your second picture:
dataGridView1.Rows.Add(9);
// for days column (1st column)
dataGridView1[0,0].Value = "Monday";
dataGridView1[0,3].Value = "Tuesday";
dataGridView1[0,6].Value = "Wednesday";
// for hours column (3rd column)
dataGridView1[2,0].Value = "7:00 - 8:00";
dataGridView1[2,1].Value = "8:00 - 9:00";
dataGridView1[2,3].Value = "7:00 - 7:50";
dataGridView1[2,4].Value = "7:50 - 8:20";
Basically
dataGridView[Column index, Row index].Value is the cell value at those coordinates
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can anybody tell me what is the difference between these two functions in C#? TotalDays and Days because I'm not sure which once I should use in my code? Sorry for the low information on this text, but there is not much I can talk about.
Since i haven't found a duplicate i post my comment here:
Always read the documentation first. TotalDays is a double because it represents whole and fractional days whereas Days is an int which represents only whole days.
That is even mentioned explicitly in the remarks sections of TimeSpan.Days/TotalDays:
The Days property represents whole days, whereas the TotalDays
property represents whole and fractional days.
One thing to note, as opposed to the other properties in TimeSpan like Hours/TotalHours there is no limit on Days. So it doesn't end with 30 or 365(like Hour which ranges from -23 through 23) since there is no larger unit than year. So Days will always be the same number as (int) ts.TotalDays.
A TimeSpan doesn't have a sensible concept of "years" because it
depends on the start and end point. (Months is similar - how many
months are there in 29 days? Well, it depends...) [J. Skeet]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am using Microsoft Visual Developer C#. I am trying to validate a textbox so that the Book Code (int) entered is exactly 4 characters long. I used the Range Validator control to do so. For the MaximumValue and MinimumValue properties of the Range Validator I made them both equal 4. However this doesnt seem to work. Am I doing it wrong?
This is very simple, you should probably be thinking more about your problem before posting. However, I will empathize with a beginner and give a couple of solutions.
option 1 - convert to a string and check it's length;
string myVar = BookCode.ToString()
if (myVar.Length < 5)
// it's good!
else
// ERROR
option 2 - the largest value less than ten thousand is 9999, a four digit value.
if (BookCode < 10000)
// it's good
else
// it's bad
If you're just having users enter text into a text box and once they press some type of submit button you want to confirm that the text is 4 characters long then you can check that with inputControl.Text.Length == 4
from there you can show a message box and return if it's not equal to 4 or continue if it is.