DataGridViewCell value is updating but new value is not displayed on screen
I have a DataGridView with one particular cell that allows the user to
adjust the day of the current week by simply focusing on that cell and
scrolling the mouse wheel up and down. The code works no problem, the
value is indeed updated but it does not show the new value until I
change focus to another cell.
private void dataGridView1_MouseWheel(object sender, MouseEventArgs e)
{
try
{
DataGridViewRow dgvRow = dataGridView1.CurrentRow;
if (dgvRow.Cells[clockDateDataGridViewTextBoxColumn.Name].Selected)
{
//increase day component of the ClockDate up to a maximum of (Start of this week + 6)
DateTime minDate = formClasses.getFirstDayOfWeek(monthCalendar1.SelectionStart);
DateTime maxDate = formClasses.getLastDayOfWeek(monthCalendar1.SelectionStart);
DateTime clockDate = DateTime.Parse(dgvRow.Cells[clockDateDataGridViewTextBoxColumn.Name].Value.ToString());
if (e.Delta >= 120 && clockDate.CompareTo(maxDate) < 0)
{
//add 1 day to the current value
dgvRow.Cells[clockDateDataGridViewTextBoxColumn.Name].Value = clockDate.AddDays(1).ToShortDateString();
}
else if (e.Delta <= -120 && clockDate.CompareTo(minDate) > 0)
{
//subtract 1 day from the current value
dgvRow.Cells[clockDateDataGridViewTextBoxColumn.Name].Value = clockDate.AddDays(-1).ToShortDateString();
}
}
}
catch (....)
When the use scrolls the mouse up or down a notch I want the date in
the cell to be updated then, I don't want it to display the original
value until moving focus away. The exact same problem happens with another cell in my DataGridView where I want to add 15 minutes onto the time after scrolling the wheel upwards. There's no cell refresh method of sorts
that I can immediately see anywhere - any ideas?
Another thing - when I scroll once upwards with the mousewheel, it fired the _MouseWheel event twice so I always get 2 days added on. I could make it add half a day on each scroll, but would rather sort it properly - why is the event being fired twice?

