private void comboBoxOrderBy_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxOrderBy.Text == "Id") { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar.GetAll().OrderBy(x => x.id).ToList(); } else if (comboBoxOrderBy.Text == "Brand") { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar.GetAll().OrderBy(x => x.Brand).ToList(); } else if (comboBoxOrderBy.Text == "Vin") { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar.GetAll().OrderBy(x => x.Vin).ToList(); } else if (comboBoxOrderBy.Text == "Year") { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar.GetAll().OrderBy(x => x.Year).ToList(); } else if (comboBoxOrderBy.Text == "Model") { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar.GetAll().OrderBy(x => x.Model).ToList(); } }
public void ShowCars() { dataGridViewCar.DataSource = null; dataGridViewCar.DataSource = _readRepositoryCar .GetAll() .Select(x => new { id = x.id, Vin = x.Vin, Brand = x.Brand, Model = x.Model, Fuel = x.Fuel, Year = x.Year, Description = x.Description, Avaliable = x.available }) .ToList(); }