我想控制dataGridVeiw的删除操作,当符合某种条件时,则可删除,反之,则不删除

解决方案 »

  1.   

    主要是添加控制逻辑到RowDeleting事件。 
     void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e)
      {
        
        // Cancel the delete operation if the user attempts to remove
        // the last record from the GridView control.
        if (CustomersGridView.Rows.Count <= 1)
        {
            
          e.Cancel = true;
          Message.Text = "You must keep at least one record.";
                
        }
        
      } 另外纠正一点,应该是GridView,不是DataGridView