# .NET and More > WPF, WCF, WF >  [RESOLVED] WPF: How to Import data from Excel to DataGrid?

## Kram Kramer

Following code is okey in the WinForm Application.

http://vb.net-informations.com/datag...iew_import.htm

I need WPF version of that WinForm code.

Note: *DataGridView* is named *DataGrid* in the WPF.

----------


## Prahlad

private void button1_Click_1(object sender, EventArgs e)  
{  
    OpenFileDialog fdlg = new OpenFileDialog();  
    fdlg.Title = "Select file";  
    fdlg.InitialDirectory = @"c:";  
    fdlg.FileName = txtFileName.Text;  
    fdlg.Filter = "Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*";  
    fdlg.FilterIndex = 1;  
    fdlg.RestoreDirectory = true;  
    if (fdlg.ShowDialog() == DialogResult.OK)  
    {  
        txtFileName.Text = fdlg.FileName;  
        Import();  
        Application.DoEvents();  
    }  
}

----------


## Prahlad

private void button1_Click_1(object sender, EventArgs e)  
{  
    OpenFileDialog fdlg = new OpenFileDialog();  
    fdlg.Title = "Select file";  
    fdlg.InitialDirectory = @"c:";  
    fdlg.FileName = txtFileName.Text;  
    fdlg.Filter = "Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*";  
    fdlg.FilterIndex = 1;  
    fdlg.RestoreDirectory = true;  
    if (fdlg.ShowDialog() == DialogResult.OK)  
    {  
        txtFileName.Text = fdlg.FileName;  
        Import();  
        Application.DoEvents();  
    }  
}

----------

