把DataGrid 的readonly属性设置为true

解决方案 »

  1.   

    同意楼上的,改ReadOnly属性。
      

  2.   

    把DataGrid 的readonly属性设置为true
      

  3.   

    改這有什么用﹐人家肯定是要修改的﹐只是禁止鍵而已
    試一下先捕獲鍵﹐然后E.CANCEL=TRUE;
      

  4.   

    最简单的方法,你在后台不写delete函数的内容,点击不就没有任何执行吗,啊哈哈
      

  5.   

    用KeyPress事件把delete屏蔽掉就OK了
      

  6.   

    private void dgTasks_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter) 
    {
    ShowTaskFormFromDataGrid();

    else if (e.KeyCode == Keys.Delete) 
    {
    DialogResult mbResult = MessageBox.Show(m_ResourceManager.GetString("Are_you_sure_you_want_to_delete"), m_ResourceManager.GetString("Confirm_Task_Delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
    this.Refresh(); if (mbResult == DialogResult.Yes) 
    {
    int taskID = GetSelectedTaskID();
    DataRow dr = m_DataLayer.DsTasks.Tasks.Rows.Find(taskID); if (dr != null) 
    dr["IsDeleted"] = true; UpdateTasks();
    }
    }
    }
      

  7.   

    可以用系统检测到按DELETE键时,将它禁用,离开DELETE时开放DELETE键
    或者写空代码来禁用DELETE键
      

  8.   

    Key_down 根本不会触发就删除了
      

  9.   

    不要在dataGrid里面写删除的代码,另外写一个方法,当点删除按钮以后获取当前行的记录号,然后调用你写的删除方法
      

  10.   

    我说的删除按钮不是dataGrid里的删除按钮,是单独的一个按钮
      

  11.   

    dataGrid1.DataSource=dataTable1;
    dataTable1.DefaultView.AllowDelete=false;
      

  12.   

    DataGrid1.Columns[0].Visible =false;
    将按钮列屏蔽,Columns[]中的数字为按钮列在datagrid中的列数
    仅供参考。
      

  13.   

    datagrid的经典问题了,经常有人问,看:
    How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key?
    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q
      

  14.   

    DG.DataSource=dv;
    dv.AllowDelete=false;
      

  15.   

    如何加private void dgTasks_KeyDown这个事件呢?

    private void InitializeComponent()
    {
    this.dgTasks.KeyDown += new System.Windows.Forms.KeyPressEventHandler(this.dgTasks_KeyDown);
    }中把事件加近来总是说类型不一样的错