From ad382764b6d578c1251f4853f793ec75e230f88e Mon Sep 17 00:00:00 2001 From: Blauschleim Date: Mon, 16 May 2022 19:49:37 +0200 Subject: [PATCH] export button now only available if any user is selected --- Form1.Designer.cs | 3 ++- Form1.cs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index dbce63a..0557b34 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -60,6 +60,7 @@ namespace it_projekt // // exportBtn // + this.exportBtn.Enabled = false; this.exportBtn.Location = new System.Drawing.Point(480, 80); this.exportBtn.Name = "exportBtn"; this.exportBtn.Size = new System.Drawing.Size(75, 23); @@ -119,7 +120,7 @@ namespace it_projekt this.dataGrid.RowTemplate.Height = 25; this.dataGrid.Size = new System.Drawing.Size(743, 225); this.dataGrid.TabIndex = 7; - this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGrid_CellContentClick); + this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellClick); // // Id // diff --git a/Form1.cs b/Form1.cs index 80d680e..e960b84 100644 --- a/Form1.cs +++ b/Form1.cs @@ -48,13 +48,18 @@ namespace it_projekt this.dataGrid.Rows.Add(person.Id, person.Firstname, person.Lastname, person.Department_short, person.Department_long, person.CreationDate, false); } this.loginBtn.Enabled = false; - this.exportBtn.Enabled = true; } } private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { + + } + private System.EventHandler test() + { + this.exportBtn.Enabled = false; + return null; } private void export(string Filter, string FileName) @@ -120,5 +125,31 @@ namespace it_projekt { } + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + //Check to ensure that the row CheckBox is clicked. + if (e.RowIndex >= 0 && e.ColumnIndex == 6) + { + //Reference the GridView Row. + DataGridViewRow row = dataGrid.Rows[e.RowIndex]; + + //Set the CheckBox selection. + row.Cells[6].Value = Convert.ToBoolean(row.Cells[6].EditedFormattedValue); + exportBtn.Enabled = false; + //If CheckBox is checked, display Message Box. + if (Convert.ToBoolean(row.Cells[6].Value)) + { + exportBtn.Enabled = true; + } + foreach (DataGridViewRow r in dataGrid.Rows) + { + if (Convert.ToBoolean(r.Cells[6].Value)) + { + exportBtn.Enabled = true; + } + } + } + } + } }