//Reset "hint" on leave if nothing was written private void cell_Leave(object sender, EventArgs e) { TextBox cell = (TextBox)sender; //Reset default value on leave, if nothing was written CheckForDummies(cell); //If military time, and in columns of military time, then proceed if (timeAreas.IndexOf(ParseCellName(cell.Name)[2]) != -1 && cell.Text != "") { if (!UtilDotNET.ValidateMilitaryTextFormat(cell.Text)) //Leaving empty cell { cell.Text = "0000"; cell.ForeColor = Color.DarkGray; } else { //Update grid cell with valid time input GridCellUpdate(cell); //Check valid time input: greater than previous //- Date format known to be valid (tryparse exact in validatemilitary...) DateTime dateLeaving = DateTime.ParseExact(cell.Text, "HHmm", CultureInfo.InvariantCulture, DateTimeStyles.None); Point pos = GridPos(cell); int movingLeft = pos.Y; while (movingLeft > 0) //Columns to the left { movingLeft--; //Starting for first column to the left of current cell string comparisonText = grid[pos.X][movingLeft]; //Text from left cell DateTime tempDate; if (DateTime.TryParseExact(comparisonText, "HHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out tempDate)) { //Pass - text is military time if (tempDate > dateLeaving) //Break; after check against a military time { cell.Text = "0000"; cell.ForeColor = Color.DarkGray; } break; } } } } }
//Clear cells on click private void cell_Click(object sender, EventArgs e) { TextBox cell = (TextBox)sender; if (allCells.Contains(cell)) { //If cell has dummy if (dummies.IndexOf(cell.Text) != -1) { cell.Text = ""; cell.ForeColor = SystemColors.WindowText; //WindowText is the default color for text boxes } if (UtilDotNET.ValidateMilitaryTextFormat(cell.Text)) { //Upgrade grid cell with new info GridCellUpdate(cell); //Display Hours double hrs = CalculateHours(); lblTotal.Text = Math.Round(hrs, 1).ToString(); } } }