//新增 private void button1_Click(object sender, EventArgs e) { Books book= new Books(); book.BuyPrice = 10; book.BuyDate = DateTime.Now; currBook = book; button2.Enabled = true; }
//点击网格 private void dataGridView1_Click(object sender, EventArgs e) { if (dataGridView1.CurrentCell == null) return; int rowindex = dataGridView1.CurrentCell.RowIndex; DataTable dt = (DataTable)dataGridView1.DataSource; Books book = new Books(); book.Id = Convert.ToInt32(dt.Rows[rowindex]["Id"]); book.BookName = dt.Rows[rowindex]["BookName"].ToString(); book.BuyPrice = Convert.ToDecimal(dt.Rows[rowindex]["BuyPrice"]); book.BuyDate = Convert.ToDateTime(dt.Rows[rowindex]["BuyDate"]); book.Flag = Convert.ToInt32(dt.Rows[rowindex]["Flag"]); currBook = book; }