Popular Combobox DataGrid Windows Forms C #

1

I have a datagrid (c # windows forms) that I need to use for editing and I'm populating with information coming from the database of a table called "costs"

TheChartofaccountsandCostCenterfieldsarepopulatedwithinformationstoredinthe"costs" table. I have two other tables (PlanoConta and Centro Custo). My idea is to click on the account plan or cost center and bring the data from the respective tables. I set the field as shown:

ButwhenclickingonthefielditdoesnotbringmethedatafromthePlanoContastable. Thanks for the help!

    
asked by anonymous 04.10.2017 / 14:44

2 answers

0

I managed to solve it! I am populating via code as below:

        FinanceiroDbContext db = new FinanceiroDbContext();

        PlanoConta.ValueMember = "Nome";
        PlanoConta.DisplayMember = "Nome";
        PlanoConta.DataSource = db.PlanoContas.ToList();
        CentroCusto.ValueMember = "Nome";
        CentroCusto.DisplayMember = "Nome";
        CentroCusto.DataSource = db.CentroCusto.ToList();
        GridRateio.DataSource = db.ExtratoCentroCusto.Where(x => x.NControl == ids).ToList();

What I did, the popular combobox was popular before the datagrid! Thanks everyone for the help !!!

    
06.10.2017 / 19:54
0

Using BindingSource you would need to create one for each ComboBox. A planoContasBidingSource and another centroCustoBidingSource , load them with the data and configure them to be DataSource of their respective combobox, as you did in the image. It's missing the data, so I understand.

For this configuration to work, you need to use the BindingSource with the data of your tables. If you post the methods you use to perform the queries, it is easier to help you! Try to return IList<T> of your query methods in the database so you can assign the results to BidingSource more easily.

    
06.10.2017 / 18:13