I'm wanting to pass data to a gridview that I have in the interface called dataGridView1
But in the add button I get an error in the BindDataGridView event, you can give me an orientation on the solution
private void btnAgregr_Click(object sender, EventArgs e)
{
var rowsChecked = this.DataKitchenArea.AsEnumerable().Where(r => Convert.ToBoolean(r["Sel"]));
foreach (DataRow rowOrigen in rowsChecked)
{
DataRow rowDestino = this.DataTableSection.NewRow();
rowDestino["Sel"] = false;
rowDestino["Id"] = rowOrigen["Id"];
rowDestino["Nombre"] = rowOrigen["Nombre"];
this.DataTableSection.Rows.Add(rowDestino);
}
this.dataGridView1.BindDataGridView(this.DataTableSection);
}
Remove button:
To delete the rows of the selected checkboxes I have this code private void BtnRemove_Click (object sender, EventArgs e) {
if (dataGridView1.SelectedRows == null)
{
MessageBox.Show("Debes seleccionar una fila del grid");
return;
}
var dt = (DataTable)dataGridView1.DataSource;
foreach (DataGridViewRow item in dataGridView1.SelectedRows)
{
var row = dt.AsEnumerable().FirstOrDefault(r => r["Id"] == item.Cells["Id"].Value);
if (row != null)
{
dt.Rows.Remove(row);
}
}
Remove button does nothing (although it has code) It's winform in c # Beforehand, thanks