Problem with popular DataGrid

1

I'm making the population a DataGrid , but I do not know why it's not showing.

Result:

Onlyemptyrowsarereturned.

Inspection.cs

publicclassFiscalizacoes{privateStringConcessionaria{get;set;}privateStringMunicipio{get;set;}privateStringSistemas{get;set;}privateDateTimeDataInicio{get;set;}privateDateTimeDataFim{get;set;}privateStringStatus{get;set;}publicFiscalizacoes(){}publicFiscalizacoes(Stringconcessionaria,Stringmunicipio,Stringsistemas,DateTimedatainicio,DateTimedatafim,Stringstatus){Concessionaria=concessionaria;Municipio=municipio;Sistemas=sistemas;DataInicio=datainicio;DataFim=datafim;Status=status;}}

populaGrid()

privatestaticIEnumerable<Fiscalizacoes>popularGrid(){varlistaFiscalizacao=newList<Fiscalizacoes>{newFiscalizacoes("SABESP", "São Paulo", "Abastecimento Água", new DateTime(2014, 12, 1),
                    new DateTime(2014, 12, 10), "Não Respondido"),
                new Fiscalizacoes("Mairinque", "Taubaté", "Esgotamento Sanitário", new DateTime(2014, 12, 1),
                    new DateTime(2014, 12, 10), "Respondido"),
                new Fiscalizacoes("Foz Gertrudes", "São José dos Campos", "Esgotamento Sanitário", new DateTime(2014, 12, 1),
                    new DateTime(2014, 12, 10), "Transmitido")
            };

            return listaFiscalizacao;
        }

XAML

<DataGrid x:Name="dataGridFiscalizacoes" ItemsSource="{Binding listaFiscalizacao}" AutoGenerateColumns="False" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Concessionária" Binding="{Binding Concessionaria}" />
                    <DataGridTextColumn Header="Município" Binding="{Binding Municipio}" />
                    <DataGridTextColumn Header="Sistemas" Binding="{Binding Sistemas}" />
                    <DataGridTextColumn Header="Data Início" Binding="{Binding DataInicio}" />
                    <DataGridTextColumn Header="Data Fim" Binding="{Binding DataFim}" />
                    <DataGridTextColumn Header="Status Checklist" Binding="{Binding Status}" />
                </DataGrid.Columns>
            </DataGrid>

window

 public ChecklistListagem(InicioWindow w)
        {
            InitializeComponent();
            this.w = w;
            dataGridFiscalizacoes.ItemsSource = popularGrid();
        }
    
asked by anonymous 02.12.2014 / 13:20

1 answer

1

I do not usually work with Binding this way. I'll put down how I use it.

First:

In DataGrid just point ItemsSource to Binding . And add in Binding o Path :

    <DataGrid x:Name="dataGridFiscalizacoes" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
                    <DataGridTextColumn Header="Concessionária" Binding="{Binding Path=Concessionaria, Mode=OneWay}" />
                    <DataGridTextColumn Header="Município" Binding="{Binding Path=Municipio, Mode=OneWay}" />
                    <DataGridTextColumn Header="Sistemas" Binding="{Binding Path=Sistemas, Mode=OneWay}" />
                    <DataGridTextColumn Header="Data Início" Binding="{Binding Path=DataInicio, Mode=OneWay}" />
                    <DataGridTextColumn Header="Data Fim" Binding="{Binding Path=DataFim, Mode=OneWay }" />
                    <DataGridTextColumn Header="Status Checklist" Binding="{Binding Path=Status, Mode=OneWay}" />
                </DataGrid.Columns>

Second:

You need to associate ItemsSource with some event. I'll assume it's in the% constructor%:

public MinhaWindow(){
    dataGridFiscalizacoes.ItemsSource = popularGrid();
}

Third:

As @JônatasHudler put in the comments the properties of the class need to be public:

public class Fiscalizacoes
    {
        public String Concessionaria { get; set; }
        public String Municipio { get; set; }
        public String Sistemas { get; set; }
        public DateTime DataInicio { get; set; }
        public DateTime DataFim { get; set; }
        public String Status { get; set; }
}
    
02.12.2014 / 13:29