From e7e8f5a944e7d01439bfff9014aa18b6be1d5e87 Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:41:28 -0500 Subject: [PATCH] implemented open form edit on row double click --- .idea/.idea.CNSA-212-Personal-CAS/.idea/.name | 1 - Database3/frmSearch.Designer.cs | 73 ++++++++++--------- Database3/frmSearch.cs | 40 ++++++++++ 3 files changed, 79 insertions(+), 35 deletions(-) delete mode 100644 .idea/.idea.CNSA-212-Personal-CAS/.idea/.name diff --git a/.idea/.idea.CNSA-212-Personal-CAS/.idea/.name b/.idea/.idea.CNSA-212-Personal-CAS/.idea/.name deleted file mode 100644 index 55a451c..0000000 --- a/.idea/.idea.CNSA-212-Personal-CAS/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -CNSA-212-Personal-CAS \ No newline at end of file diff --git a/Database3/frmSearch.Designer.cs b/Database3/frmSearch.Designer.cs index fde9994..fdb86ab 100644 --- a/Database3/frmSearch.Designer.cs +++ b/Database3/frmSearch.Designer.cs @@ -32,17 +32,17 @@ this.components = new System.ComponentModel.Container(); this.lblDisStID = new System.Windows.Forms.Label(); this.dgvStudents = new System.Windows.Forms.DataGridView(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.cmuSearch = new System.Windows.Forms.ToolStripMenuItem(); + this.cmuEdit = new System.Windows.Forms.ToolStripMenuItem(); + this.cmuDelete = new System.Windows.Forms.ToolStripMenuItem(); this.lblDislname = new System.Windows.Forms.Label(); this.lblDisDOB = new System.Windows.Forms.Label(); this.txtStuID = new System.Windows.Forms.TextBox(); this.txtlname = new System.Windows.Forms.TextBox(); this.txtDOB = new System.Windows.Forms.TextBox(); this.btnSearch = new System.Windows.Forms.Button(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.cmuSearch = new System.Windows.Forms.ToolStripMenuItem(); - this.cmuEdit = new System.Windows.Forms.ToolStripMenuItem(); - this.cmuDelete = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dgvStudents)).BeginInit(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -59,11 +59,44 @@ // dgvStudents // this.dgvStudents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvStudents.ContextMenuStrip = this.contextMenuStrip1; this.dgvStudents.Location = new System.Drawing.Point(77, 250); this.dgvStudents.Name = "dgvStudents"; + this.dgvStudents.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgvStudents.Size = new System.Drawing.Size(638, 150); this.dgvStudents.TabIndex = 1; // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripSeparator1, this.cmuSearch, this.cmuEdit, this.cmuDelete }); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(110, 76); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(106, 6); + // + // cmuSearch + // + this.cmuSearch.Name = "cmuSearch"; + this.cmuSearch.Size = new System.Drawing.Size(109, 22); + this.cmuSearch.Text = "Search"; + this.cmuSearch.Click += new System.EventHandler(this.cmuSearch_Click); + // + // cmuEdit + // + this.cmuEdit.Name = "cmuEdit"; + this.cmuEdit.Size = new System.Drawing.Size(109, 22); + this.cmuEdit.Text = "Edit"; + this.cmuEdit.Click += new System.EventHandler(this.cmuEdit_Click); + // + // cmuDelete + // + this.cmuDelete.Name = "cmuDelete"; + this.cmuDelete.Size = new System.Drawing.Size(109, 22); + this.cmuDelete.Text = "Delete"; + // // lblDislname // this.lblDislname.Location = new System.Drawing.Point(206, 108); @@ -88,6 +121,7 @@ this.txtStuID.Name = "txtStuID"; this.txtStuID.Size = new System.Drawing.Size(132, 20); this.txtStuID.TabIndex = 4; + this.txtStuID.TextChanged += new System.EventHandler(this.txtStuID_TextChanged); // // txtlname // @@ -113,35 +147,6 @@ this.btnSearch.UseVisualStyleBackColor = true; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // - // contextMenuStrip1 - // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripSeparator1, this.cmuSearch, this.cmuEdit, this.cmuDelete }); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(110, 76); - // - // toolStripSeparator1 - // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(106, 6); - // - // cmuSearch - // - this.cmuSearch.Name = "cmuSearch"; - this.cmuSearch.Size = new System.Drawing.Size(109, 22); - this.cmuSearch.Text = "Search"; - // - // cmuEdit - // - this.cmuEdit.Name = "cmuEdit"; - this.cmuEdit.Size = new System.Drawing.Size(109, 22); - this.cmuEdit.Text = "Edit"; - // - // cmuDelete - // - this.cmuDelete.Name = "cmuDelete"; - this.cmuDelete.Size = new System.Drawing.Size(109, 22); - this.cmuDelete.Text = "Delete"; - // // frmSearch // this.AcceptButton = this.btnSearch; diff --git a/Database3/frmSearch.cs b/Database3/frmSearch.cs index 57567a9..c56a5d7 100644 --- a/Database3/frmSearch.cs +++ b/Database3/frmSearch.cs @@ -9,9 +9,33 @@ namespace Database3 { public partial class frmSearch : Form { + + public static string myID = ""; + public frmSearch() { InitializeComponent(); + + dgvStudents.DoubleClick += new EventHandler(dgvStudents_DoubleClick); + + } + + private void dgvStudents_DoubleClick(object sender, EventArgs e) + { + + string studentid = ""; + + if (dgvStudents.Rows.Count > 0) + { + DataGridViewRow row = dgvStudents.SelectedRows[0]; + frmEdit aform = new frmEdit(); + + studentid = row.Cells[0].Value.ToString().Trim(); + myID = studentid; + aform.ShowDialog(); + + } + } private void btnSearch_Click(object sender, EventArgs e) @@ -75,6 +99,22 @@ namespace Database3 } private void frmSearch_Load(object sender, EventArgs e) + { + dgvStudents.Visible = false; + contextMenuStrip1.Items[1].Enabled = false; + } + + private void cmuSearch_Click(object sender, EventArgs e) + { + btnSearch_Click(sender,e); + } + + private void txtStuID_TextChanged(object sender, EventArgs e) + { + cmuSearch.Enabled = txtStuID.Text.Length>0; + } + + private void cmuEdit_Click(object sender, EventArgs e) { }