private void CargarGridPropiedades()
        {
            PropiedadesDataSource                   = new BindingList <Propiedades>(PropiedadesBL.GetPropiedades());
            dataGridView1.DataSource                = PropiedadesDataSource;
            dataGridView1.Columns["Id"].Visible     = false;
            dataGridView1.Columns["Activo"].Visible = false;

            dataGridView1.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.AllCells;
            dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            //dataGridView1.AjustColumnsWidthForGridWidth();
            //dataGridView1.Columns[2].Width = 300;
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            if (ValidarCampos())
            {
                List <Propiedades> lpropi = new List <Propiedades>();
                Propiedades        Propi  = new Propiedades();

                Propi.Codigo      = txtCodigo.Text;
                Propi.Descripcion = txtDescrpcion.Text;
                Propi.Activo      = materialCheckBox1.Checked ? 1 : 0;

                switch (labelNoMouse1.Text.Trim())
                {
                case "Agregar":
                    lpropi.Add(Propi);
                    PropiedadesBL.InserPropiedades(lpropi);

                    CargarGridPropiedades();
                    // LimpiarCampos();
                    dataGridView1.Rows[(dataGridView1.RowCount - 1)].Selected = true;
                    dataGridView1.FirstDisplayedScrollingRowIndex             = dataGridView1.RowCount - 1;
                    dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[2];

                    CargarCampos(dataGridView1.RowCount - 1);
                    break;

                case "Actualizar":
                    Propi.id = Convert.ToInt32(dataGridView1[0, dataGridView1.CurrentRow.Index].Value);
                    lpropi.Add(Propi);
                    PropiedadesBL.UpdatePropiedades(lpropi);

                    int nRow = dataGridView1.CurrentRow.Index;
                    CargarGridPropiedades();

                    dataGridView1.Rows[nRow].Selected = true;
                    dataGridView1.CurrentCell         = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[2];
                    break;
                }
            }
        }