datagridview loaded only one data then i clicked SelectALL but row not selected What I have tried: private void ReportViewer_Load(object sender, EventArgs e) { grdEmailData.ColumnHeaderMouseClick += grdEmailData_ColumnHeaderMouseClick; } private void btnSearch_Click(object sender, EventArgs e) { try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = "SELECT * FROM email_notification WHERE bank_code = @BankCode AND stmdate = @StmDate " + "UNION " + "SELECT * FROM email_notification_arc WHERE bank_code = @BankCode AND stmdate = @StmDate"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@BankCode", _fiid); // Assuming _serverName is the bank code command.Parameters.AddWithValue("@StmDate", dtpStmDate.Value.ToString("dd/MM/yyyy")); SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn(); checkBoxColumn.HeaderText = "SelectALL"; checkBoxColumn.Name = "All"; grdEmailData.Columns.Insert(0, checkBoxColumn); // Bind the data to the DataGridView grdEmailData.DataSource = dataTable; } } } catch (Exception ex) { MessageBox.Show($"Error loading data: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void grdEmailData_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { // Check if the clicked cell is in the "All" column header if (e.RowIndex == -1 && e.ColumnIndex == grdEmailData.Columns["All"].Index) { ToggleSelectAll(); } } private void ToggleSelectAll() { // Toggle the select/unselect all logic in the "All" column bool selectAll = true; foreach (DataGridViewRow row in grdEmailData.Rows) { DataGridViewCheckBoxCell checkBoxCell = row.Cells["All"] as DataGridViewCheckBoxCell; if (checkBoxCell != null) { checkBoxCell.Value = selectAll; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)