Esempio n. 1
0
 void _dgv_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         foreach (DataGridViewCell cell in _dgv.SelectedCells)
         {
             IExamCell ic = cell.Tag as IExamCell;
             if (ic == null)
             {
                 continue;
             }
             cell.Value = "";
             ic.SetValue("");
             CellEdited(cell, ic);
         }
     }
     //else if (e.KeyCode == Keys.Control | e.KeyCode == Keys.V)
     //{
     //    string value = Clipboard.GetText();
     //    string[] rowValues = value.Split('\n');
     //    XmlDocument doc = new XmlDocument();
     //    XmlElement root = doc.CreateElement("RootElement");
     //    foreach (string rowValue in rowValues)
     //    {
     //        XmlElement rowElement = doc.CreateElement("");
     //    }
     //}
 }
Esempio n. 2
0
        private void CellEdited(DataGridViewCell cell, IExamCell icell)
        {
            DataGridViewCellStyle style = cell.DataGridView.Rows[cell.RowIndex].Cells[0].Style;
            Color defaultBackColor      = style.BackColor;
            Color defaultForeColor      = style.ForeColor;

            cell.Style.BackColor = defaultBackColor;
            cell.Style.ForeColor = defaultForeColor;
            cell.ToolTipText     = "";

            string value = cell.Value == null ? "" : cell.Value.ToString().Trim();

            cell.Value = value;

            if (icell != null)
            {
                icell.SetValue(value);
                if (icell.IsValid())
                {
                    icell.Standard.Judge(cell);
                    if (icell.IsDirty)
                    {
                        cell.Style.BackColor = Color.Yellow;
                        cell.ToolTipText     = "此欄位值已變更,其原值為『" + icell.DefaultValue + "』";
                    }
                }
                else
                {
                    cell.Style.BackColor = Color.Red;
                    cell.Style.ForeColor = defaultForeColor;
                    cell.ToolTipText     = "錯誤!!此欄位必須為數字";
                }
            }

            if (DirtyChanged != null)
            {
                DirtyChanged.Invoke(this, new DirtyChangedEventArgs(IsDirty()));
            }
        }