• WPF学习笔记-BeginningEdit和CellEditEnding


    BeginningEdit  在行或单元格进入编辑模式之前发生

    CellEditEnding  在单元格编辑器执行或取消之前发生

    <DataGrid  Name="AlarmDataDG" BeginningEdit="AlarmDataDG_BeginningEdit" CellEditEnding="AlarmDataDG_CellEditEnding"/>
    private void AlarmDataDG_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
    {
        TextBlock tbl = e.Column.GetCellContent(e.Row) as TextBlock;
        if(tbl == null)
        {
            return;
        }
        _oldvalue = (e.Column.GetCellContent(e.Row) as TextBlock).Text;
        _columnName = e.Column.Header.ToString();
    }
    
    private void AlarmDataDG_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
       if (!(e.EditingElement is TextBox tb))
           return;
       string newValue = tb.Text;
    
       if (AlarmDataDG.SelectedItem != null)
       {
          if (newValue != _oldvalue)
          {
              Base_Error_ListEntity model = AlarmDataDG.SelectedItem as Base_Error_ListEntity;
              StringBuilder strSql = new StringBuilder();
              strSql.Append($"update base_error_list set ");
              switch (_columnName)
               {
                  case "报警原因":
                      strSql.Append($"yy = '{newValue}' ");
                      break;
                  case "采取措施":
                      strSql.Append($"cqcs = '{newValue}' ");
                      break;
                  case "责任人":
                      strSql.Append($"zrr = '{newValue}' ");
                      break;
                }
               strSql.Append($"where id = '{model.Id}'");
    
               using (var db = new FrameContext())
               {
                   int ret = db.Database.ExecuteSqlCommand(strSql.ToString());
                   if(ret <= 0)
                   {
                        MessageBox.Show("更新字段失败,请重试!", "提示", MessageBoxButton.OK);
                   }
                }
          }
        }
    
    }
    
    
    
    
    
  • 相关阅读:
    973. K Closest Points to Origin
    919. Complete Binary Tree Inserter
    993. Cousins in Binary Tree
    20. Valid Parentheses
    141. Linked List Cycle
    912. Sort an Array
    各种排序方法总结
    509. Fibonacci Number
    374. Guess Number Higher or Lower
    238. Product of Array Except Self java solutions
  • 原文地址:https://www.cnblogs.com/gxsxc/p/10132925.html
Copyright © 2020-2023  润新知