Data does not appear in the datagridview, even when setting a populated datasource, Why?

-1

I'm trying to capture some information from the database, filter it, and then do validation tests on each of the returned rows. Then I try to get the rows that failed the test and insert into a new datatable. However, after having the datatable filled in and associated with the datagridview as a datasource, the data does not appear in the datagridview object.

What can it be?

    Dim Aviso As New frmWarning
    Dim Filtros As String
    Dim DtTable As New DataTable
    Dim DtView As DataView

    Aviso.Abrir()

    Filtros = "Data >= '" & DtInicial.Text & "'"
    Filtros = Filtros & " and Data <= '" & DtFinal.Text & "'"
    Filtros = Filtros & " and Loja = " & Me.cmbLojas.SelectedValue

    With dgvCPF
        .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        .DataSource = Nothing
        .ColumnCount = 7
        .Columns(0).Name = "TipoDaNota"
        .Columns(0).DataPropertyName = "TipoDaNota"
        .Columns(1).Name = "CPF_CNPJ"
        .Columns(1).DataPropertyName = "CPF_CNPJ"
    End With


    If NotasTable.Rows.Count = 0 Then
        DtTable = preencheNotasImp() 'Retorna Busca de Dados
        DtView = New DataView(DtTable)
        DtView.RowFilter = Filtros ' Filtra os dados

        Dim CGC As String
        Dim DtAux As New DataTable
        DtTable = DtView.ToTable 'Retorna os dados filtrados para a antiga datatable

        For Each Row As DataRow In DtTable.Rows
            CGC = Row.Item(9).ToString()

            If ValidaCGCCPF.Validations.isCNPJ(CGC) = True Or _
                ValidaCGCCPF.Validations.isCPF(CGC) = True Then

                DtAux.ImportRow(Row) 'Importa linha 

            End If
        Next Row

        dgvCPF.DataSource = DtAux


    End If



    Aviso.Fechar()
    
asked by anonymous 16.04.2014 / 15:18

1 answer

1

Try to call the DataBind of the grid after setting the DataTable:

dgvCPF.DataSource = DtAux
dgvCPF.DataBind()
    
16.04.2014 / 20:56