C# wpf Datagrid generation

Asked

Viewed 30 times

0

I have a datagrid that is automatically generated

dgPagamentos.ItemsSource = HistoricoDoClienteViewModel.ExibirPagamentosPorCliente(id);

My problem is that this call returns me an object that contains another object, at the time of the display happens this

inserir a descrição da imagem aqui

I wanted to personalize the column 1 with the name of the Registry and not the type of the object

data grid shampooing:

<DataGrid x:Name="dgPagamentos" HorizontalAlignment="Right" Margin="0,177,57,0" Width="557" Height="163" VerticalAlignment="Top" IsReadOnly="True" />

data generation code

public static List<Pagamento> ExibirPagamentosPorCliente(int id)
    {
        List<Pagamento> pagamentos = new List<Pagamento>();
        try
        {
            using (ConsultorioContext ctx = new ConsultorioContext())
            {
                pagamentos = ctx.Pagamentos.Where(p => p.Cliente.Id == id).Include(r => r.Recebedor).ToList();

                return pagamentos;
            }
        }
        catch (Exception)
        {
            return pagamentos;
        }
    }
  • Show the XAML of dataGrid and code that generates the data.

  • edited the question, put the two dice

  • It’s happening because you’re passing the r.Recebedor and Recebedor must be a high-level class and not a fundamental field or property.

  • Within Recebedor must have some field whose name is the secretariat? Suppose that is nomeSecretaria do pagamentos = ctx.Pagamentos.Where(p => p.Cliente.Id == id).Include(r => r.Recebedor.nomeSecretaria).ToList();

  • payments = ctx.Pagamentos.Where(p => p.Cliente.Id == id). Include(r => r.Receptor.Name). Tolist(); I tried with this line but it did not take effect, I do not return anything

1 answer

0

the way I managed to fix my problem was like this

shaman

<DataGrid x:Name="dgPagamentos" HorizontalAlignment="Right" Margin="0,177,57,0" Width="557" Height="163" VerticalAlignment="Top" IsReadOnly="True" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Id" Binding="{Binding Id}"/>
            <DataGridTextColumn Header="Recebedor" Binding="{Binding Recebedor.Nome}" />
            <DataGridTextColumn Header="Forma de Pagamento" Binding="{Binding FormaDePagamento}" />
            <DataGridTextColumn Header="Data de Pagamento" Binding="{Binding DataDePagamento}" />
            <DataGridTextColumn Header="Valor" Binding="{Binding Valor}" />
        </DataGrid.Columns>
    </DataGrid>

bank consultation

pagamentos = ctx.Pagamentos.Where(p => p.Cliente.Id == id).Include(r => r.Recebedor).ToList();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.