private void bViewOwners_Click(object sender, EventArgs e) { OwnersPanel.Show(); //This is for showing the owners ds = db.getAllOwners(); dataGridView2.DataSource = ds.Tables[0]; dataGridView2.Columns[1].Width = 80; dataGridView2.Columns[1].HeaderText = "First Name"; dataGridView2.Columns[2].Width = 80; dataGridView2.Columns[2].HeaderText = "Last Name"; if (dataGridView2.ColumnCount < 4) { DataGridViewButtonColumn editButton = new DataGridViewButtonColumn(); editButton.HeaderText = "Details"; editButton.Text = "Details"; editButton.UseColumnTextForButtonValue = true; editButton.Width = 50; dataGridView2.Columns.Add(editButton); DataGridViewButtonColumn deleteButton = new DataGridViewButtonColumn(); deleteButton.HeaderText = "Delete"; deleteButton.Text = "Delete"; deleteButton.UseColumnTextForButtonValue = true; deleteButton.Width = 50; dataGridView2.Columns.Add(deleteButton); } }
private void dataGridView2_CellClick_1(object sender, DataGridViewCellEventArgs e) { Int32 selectedCellCount = dataGridView2.GetCellCount(DataGridViewElementStates.Selected); if (selectedCellCount > 0) { if (dataGridView2.AreAllCellsSelected(true)) { MessageBox.Show("All cells are selected", "Selected Cells"); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < selectedCellCount; i++) { //an attributes to know which part we selecting string condition = dataGridView2.SelectedCells[i].Value .ToString(); //this is an attribute for getting the value of rfid int idselected = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString()); //We need to create an attribute for identifying what species is our animal if (condition == "Delete") { MessageBox.Show(idselected.ToString()); DialogResult dialogResult = MessageBox.Show("Are you sure want to Delete this owner", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { db.dropOwner(idselected); HomePanel.Show(); } else if (dialogResult == DialogResult.No) { OwnersPanel.Show(); } } else if (condition == "Details") { po = db.getOwnerById(idselected); this.textBox9.Text = po.getAddress(); this.textBox14.Text = Convert.ToString(po.getOwnerId()); this.textBox10.Text = Convert.ToString(po.getPhoneOwner()); this.textBox12.Text = po.getLastName(); this.textBox13.Text = po.getFirstName(); this.dateTimePicker1.Text = Convert.ToString(po.getDob()); this.textBox11.Text = po.getEmail(); //this.tbRfidOwner.Text = animal.getRfidByOwner(po); OwnersPanel.Hide(); OwnDetailsPanel.Show(); } condition = ""; idselected = 0; } } } selectedCellCount = 0; }