0

I am trying to work with a csv file in a DataGrid. The file is made up of around 5000 rows. The program takes quite a few minutes before showing the csv file data. My code is as follow:

//_csvGrid is the datagrid
//FilePath is the path for the csv file
_csvGrid.AutoGenerateColumns = true;
dsBuilder dsb = new dsBuilder(FilePath);
_csvGrid.ItemsSource = dsb.buildDS().Tables[0].DefaultView;

Also, once the datagrid finished loading, the interaction is very slow. Any idea on how to speed things up?

Christo
  • 411
  • 7
  • 27
  • You're probably breaking UI virtualization by putting the DataGrid in an inappropriate container. Post your XAML. – Federico Berasategui Feb 09 '15 at 13:11
  • Maybe u should use paging like this http://stackoverflow.com/questions/784726/how-can-i-paginate-a-wpf-datagrid or virtualization – puko Feb 09 '15 at 13:13
  • how many columns are there? Is Paging implemented? – Anand Vyas Feb 09 '15 at 13:14
  • There is about 15 columns. Will look at paging – Christo Feb 09 '15 at 14:12
  • btw, the code for dsBuilder class is as follow: string CSVPath = System.IO.Path.GetDirectoryName(file_path); string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + CSVPath + ";Extended Properties='text;HDR=Yes;FMT=Delimited'"; string CmdText = "select * from [" + System.IO.Path.GetFileName(file_path) + "]"; OleDbConnection Con = new OleDbConnection(ConnectionString); OleDbDataAdapter adptr = new OleDbDataAdapter(CmdText, Con); DataSet Ds = new DataSet(); adptr.Fill(Ds); return Ds; – Christo Feb 09 '15 at 14:17
  • @Christo Please edit your question and include the relevant code and XAML (properly formatted) in the question body instead of putting it in comments here. This makes your code totally unreadable. – Federico Berasategui Feb 09 '15 at 14:19

1 Answers1

1

The StackPanel is breaking the UI virtualization.

Remove it or change it to a DockPanel:

<DockPanel>
    <Menu Height="37" DockPanel.Dock="Top"/> 
    <DataGrid Name="CSVgrid"/> 
</DockPanel>
Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154