Jump to content
hc19

Filtrar DataGridView carregado de dados de um excel

Recommended Posts

hc19

Boa tarde,

Queria pedir se alguem me arranja um exemplo de filtragem de um DataGridView, carregado de dados de um excel, já que não consigo resolver esse problema e todo o que conheço está relacionado com BD (base de dados)

Obrigado

Share this post


Link to post
Share on other sites
hc19

obrigado mas isso eu já tenho, o que preciso mesmo é da filtragem, ou seja, introduzir filtros.

aqui deixo o meu exemplo de abrir o excel:

Imports System.Data.OleDb
Imports Microsoft.Office.Interop

    Private da As OleDbDataAdapter
    Private dt As DataTable
    Dim conexao_Excel As String
Friend WithEvents OpenFileDialog As System.Windows.Forms.OpenFileDialog


   OpenFileDialog1.Filter = "Excel (*.xlsx)|*.xlsx|Excel (*.xls)|*.xls|Todos (*.*)|*.*"
        OpenFileDialog1.FilterIndex = 3
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.InitialDirectory = "C:\\"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            conexao_Excel = "Provider=Microsoft.ACE.OleDb.12.0;" _
                                & "data source=" & OpenFileDialog1.FileName & ";" _
                                & "Extended Properties=Excel 8.0;"
        End If
        ' cria um novo dataadapter
        da = New OleDbDataAdapter("SELECT * FROM  [folha1$]", conexao_Excel)
        dt = New DataTable
        da.Fill(dt)
        ' define a chave primaria
        dt.PrimaryKey = New DataColumn() {dt.Columns(0)}
        ' vincula o modo de visao padrão da tabela ao datagrid 
        DataGridView1.DataSource = dt.DefaultView

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.