如何删除DataGrid中显示的数据?我是用自动生成的代码形式显示DataGrid中
数据的

解决方案 »

  1.   

    这不是删除全部数据了,我只想删除我选中的一条啊,那要怎么写,
    我在删除按钮下这面这么写可以吗?,还是要怎么写?if( this.dataGrid1.CurrentRowIndex < 0 ) return;
    if( DialogResult.Yes == MessageBox.Show( "您确实要删除?", "确定", MessageBoxButtons.YesNo, MessageBoxIcon.Information ) )
    {
      SqlConnection Conn = new SqlConnection(connString );
    try
    {Conn.Open();
         SqlCommand regCmd = Conn.CreateCommand();
         string str = this.dataGrid1[ this.dataGrid1.CurrentCell ].ToString();
         if( str == "" ) return;
          string strSql = "delete from t_Sy where SyDm ='" + str + "'";
           regCmd.CommandText = strSql;
           regCmd.ExecuteNonQuery();
    }
    catch( Exception ex )
    {
    MessageBox.Show( ex.Message );
    }
    finally
    {
    Conn.Close();
    }
      

  2.   

    Dim pos As Integer
                      ds.Tables("OrderDetails").DefaultView.Sort = "COD_MITEM,COD_LOC"
                        Dim vals(1) As Object
                        vals(0) = e.Item.Cells(1).Text
                        vals(1) = "B"
                        pos = ds.Tables("OrderDetails").DefaultView.Find(vals)
                        If pos <> -1 Then
                             ds.Tables("OrderDetails").Rows(pos).Delete()                         MessagBox.Show("已經刪除")
                        End If
    然后再绑定
      

  3.   

    能删除数据库里的数据,但是结果要在第二次运行时才到看到,怎么在不添加更新按钮的情况下,让dataGrid自动更新啊?
      

  4.   

    http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
    http://blog.csdn.net/zhzuo/archive/2005/01/03/238273.aspx