Does not contain a definition for 'BinDataGridView' And delete button

0

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

    
asked by Alejandro Olivares 04.01.2019 в 20:15
source

1 answer

1

I do not know where you get the BindDataGridView but it does not exist, you should use

this.dataGridView1.DataSource = this.DataTableSection;

with the DataSource assign the data to the grid

DataGridView.DataSource Property

    
answered by 04.01.2019 / 20:20
source