コード例 #1
0
        /// <summary>
        /// 点击数据网格控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_drop")
            {
                Goods model = new Goods();
                model.Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value);
                if (GoodsHelper.Drop(model, new List <string>()
                {
                    "id"
                }))
                {
                    ShowDataGird(); MessageBox.Show("删除成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_alter")
            {
                Goods model = new Goods();
                model.Id   = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                model.sum  = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["sum"].Value);
                model.name = dataGridView1.Rows[e.RowIndex].Cells["name"].Value.ToString();
                model.type = dataGridView1.Rows[e.RowIndex].Cells["type"].Value.ToString();
                if (GoodsHelper.AlterByPK(model, "id"))
                {
                    ShowDataGird(); MessageBox.Show("修改成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }