In a WPF application, by using c#, I want users to be able to import their data to grid view. So do i need a browse button or something?
If yes how can I do that?
In a WPF application, by using c#, I want users to be able to import their data to grid view. So do i need a browse button or something?
If yes how can I do that?
The below code helps you to display the browse button
<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;
}