Exemplo n.º 1
0
        protected void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.dataGridView1.Rows[e.RowIndex].Cells["No"].ReadOnly    = true;
                this.dataGridView1.Rows[e.RowIndex].Cells["Judul"].ReadOnly = true;
                this.dataGridView1.Rows[e.RowIndex].Cells["Isi"].ReadOnly   = true;

                infoIDchoose = (int)dataGridView1.Rows[e.RowIndex].Cells["No"].Value;
                if (e.ColumnIndex == dataGridView1.Columns["Edit"].Index && e.RowIndex >= 0)
                {
                    AdminInfoEdit editInfo = new AdminInfoEdit(infoIDchoose, "Kegiatan");
                    editInfo.Show();
                }
                else if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index && e.RowIndex >= 0)
                {
                    SqlCommand command = new SqlCommand("DELETE FROM Kegiatan WHERE No=" + infoIDchoose, con);

                    if (MessageBox.Show("Are you sure want to delete this record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ExecMyQuery(command, "Data Deleted");
                    }
                }
                else
                {
                    textBoxJudul.Text = dataGridView1.Rows[e.RowIndex].Cells["Judul"].Value.ToString();
                    textBoxIsi.Text   = dataGridView1.Rows[e.RowIndex].Cells["Isi"].Value.ToString();
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 2
0
        protected void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //disable edit on datagridview
                this.dataGridView1.Rows[e.RowIndex].Cells["No"].ReadOnly    = true;
                this.dataGridView1.Rows[e.RowIndex].Cells["Judul"].ReadOnly = true;
                this.dataGridView1.Rows[e.RowIndex].Cells["Isi"].ReadOnly   = true;

                infoIDchoose = (int)dataGridView1.Rows[e.RowIndex].Cells["No"].Value;
                if (e.ColumnIndex == dataGridView1.Columns["Edit"].Index && e.RowIndex >= 0)
                {
                    AdminInfoEdit editInfo = new AdminInfoEdit(infoIDchoose, "Info");
                    editInfo.Show();
                }
                else if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index && e.RowIndex >= 0)
                {
                    SqlCommand command = new SqlCommand("DELETE FROM Info WHERE No=" + infoIDchoose, con);

                    if (MessageBox.Show("Are you sure want to delete this record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ExecMyQuery(command, "Data Deleted");
                    }
                }
                else
                {
                    textBoxJudul.Text = dataGridView1.Rows[e.RowIndex].Cells["Judul"].Value.ToString();
                    textBoxIsi.Text   = dataGridView1.Rows[e.RowIndex].Cells["Isi"].Value.ToString();
                }
            }
            catch
            {
                return;
            }

            // Ignore clicks that are not on button cells.
            //if (e.RowIndex < 0 || e.ColumnIndex !=
            // dataGridView1.Columns["edit"].Index) return;

            // Retrieve the content info ID.
            //int infoID = (Int32)dataGridView1[0, e.RowIndex].Value;

            //int selected = 0;
            //Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells["No"].Value.ToString(), out selected);
            //infoIDchoose = selected;

            //AdminInfoEdit editInfo = new AdminInfoEdit();
            //editInfo.Show();
        }