日期:2014-05-17  浏览次数:20953 次

winform中的 DataGridView 的 AllowUserToDeleteRows属性怎么设置?
//store the selected row index.
        private int selectedRowIndex = 0;
        public Form1() {
            InitializeComponent();
        }
        //Initialize the Data.
        private void Form1_Load(object sender, EventArgs e) {
            string strConnection = @"Data Source=.\SQLExpress;Initial Catalog=DB_Person;Integrated Security=True";
            using(SqlConnection connect = new SqlConnection(strConnection)) {
                SqlCommand cmd = connect.CreateCommand();
                cmd.CommandText = "select * from [T_Employee]";
                DataSet set = new DataSet();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(set, "T_Employee");
                dataGV.DataSource = set.Tables["T_Employee"];   //specify the DataSource.
                dataGV.ReadOnly = true; //read only not work when trying to delete or add rows.
                //can not add or delete rows.
                dataGV.AllowUserToAddRows = false;
                dataGV.AllowUserToDeleteRows = false;
            }
        }
        //Try to delete the DataGridView row.
        private void btn_DeleteRow_Click(object sender, EventArgs e) {