2013-02-07 37 views
2

上的按鈕,我希望用戶能夠將他們的數據導入到gridview。所以我需要一個瀏覽按鈕或某事。使用c#在WPF中瀏覽WPF

如果是的,我該怎麼辦呢?

感謝

+0

檢查這個答案:http://stackoverflow.com/a/10315283/161222 – Radi

+0

Ohhhhmmmm ......我的玻璃球說它已經壞了。用戶能從哪裏導入數據?從文件,剪貼板...你是什麼意思_browse button_? – DHN

+0

你試圖導入什麼類型的文件?您需要解析數據以填充數據網格,數據網格中沒有神奇的導入功能,您需要自己實現它。瀏覽按鈕是簡單的部分。 –

回答

12

下面的代碼可以幫助你顯示瀏覽按鈕

<TextBox Height="32" HorizontalAlignment="Left" Margin="6,10,0,0" Name="FileNameTextBox" 
       VerticalAlignment="Top" Width="393" /> 
     <Button Content="Browse" Height="32" HorizontalAlignment="Left" Margin="405,10,0,0" 
       Name="button1" VerticalAlignment="Top" Width="88" Click="button1_Click" /> 


// Create OpenFileDialog 
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();   

// Set filter for file extension and default file extension 
dlg.DefaultExt = ".txt"; 
dlg.Filter = "Text documents (.txt)|*.txt"; 

// Display OpenFileDialog by calling ShowDialog method 
Nullable<bool> result = dlg.ShowDialog(); 

// Get the selected file name and display in a TextBox 
if (result == true) 
{ 
    // Open document 
    string filename = dlg.FileName; 
    FileNameTextBox.Text = filename; 
} 
+0

感謝它的工作!但我怎樣才能使選定的文件的數據導入到我自己的WPF – hslldm