示例#1
0
 /// <summary>
 /// Assign values to specified property of Model from local DbSet and propagate changes to DGV.
 /// </summary>
 /// <typeparam name="T">Type of Model property</typeparam>
 /// <param name="prop">Name of properrty of Model or Column from dgv</param>
 /// <param name="val">Value</param>
 public void FillDbSetValues <T>(string prop, T val)
 {
     try
     {
         CellValueChanged -= RDataGridView_CellValueChanged;
         foreach (var i in SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct())
         {
             var m = CurrentDbSet.Where(mm => mm.Id == (int)Rows[i].Cells["Id"].Value).FirstOrDefault();
             if (m == null)
             {
                 continue;
             }
             var setPropValue = m.GetType().GetProperty(prop).GetSetMethod();
             setPropValue.Invoke(m, new object[] { val });
             CurrentDbSet.Update(m);
         }
         SaveChanges();
         Refresh();
         CellValueChanged += RDataGridView_CellValueChanged;
     }
     catch (Exception ex)
     {
         Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_DB_VAL)
         {
             DetailedText = string.Join(Environment.NewLine, prop, ex.Message)
         });
     }
 }
示例#2
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            List <DataGridViewCell> selectedCells = null;

            // Intercept left clicks without modifier keys.
            if (AllowMultiRowDrag &&
                (e.Button & MouseButtons.Left) == MouseButtons.Left &&
                ModifierKeys == Keys.None)
            {
                HitTestInfo hitInfo = HitTest(e.X, e.Y);

                // If the empty space is clicked then clean the selection.
                if (hitInfo.Type == DataGridViewHitTestType.None)
                {
                    ClearSelection();
                }
                // If a selected cell is clicked, remember the current selection
                // and temporary suspend the control redrawing.
                else if (hitInfo.Type == DataGridViewHitTestType.Cell &&
                         this[hitInfo.ColumnIndex, hitInfo.RowIndex].Selected)
                {
                    selectedCells      = SelectedCells.OfType <DataGridViewCell>().ToList();
                    holdedCellToSelect = this[hitInfo.ColumnIndex, hitInfo.RowIndex];
                    SendMessage(this.Handle, WM_SETREDRAW, false, 0);
                }
            }

            // Perform base processing.
            base.OnMouseDown(e);

            // Restore selection if necessary and resume the control redrawing.
            if (holdedCellToSelect != null)
            {
                ClearSelection();
                foreach (var cell in selectedCells)
                {
                    cell.Selected = true;
                }
                SendMessage(this.Handle, WM_SETREDRAW, true, 0);
            }
        }