WPF DataGrid

Hey, I want to import data from a csv file to an dataGrid. I use LINQ to split. The splitted data, what is an 2D list of strong looks okay, but

(Sorry, I am on my phone right now):

I think I add the Rows on a wrong way. I want to convert the 2D list in to a DataTable:


namespace CSVMVVM_.ViewModel { internal class PreparedData { CSV_Input input; public List<List<string>> input_data; public PreparedData() { input = new CSV_Input(); input_data = input.getList(); } public DataTable Convert2DListToDataTable() { DataTable dataTable = new DataTable(); // Erste List reihe enthält Spaltenanmen foreach(var columnName in input_data[0]) { dataTable.Columns.Add(columnName); } for (int i = 1; i < input_data.Count; i++) { dataTable.Rows.Add(input_data[i].ToArray()); } return dataTable; } } }



MainWindow.xaml.cs:

namespace CSV
MVVM_ { /// <summary> /// Interaktionslogik für MainWindow.xaml /// </summary> public partial class MainWindow : Window { PreparedData dataClass; public MainWindow() { InitializeComponent(); dataClass = new PreparedData(); } private void Button_Click(object sender, RoutedEventArgs e) { DataTable data = dataClass.Convert2DListToDataTable(); datagrid.ItemsSource = dataClass.Convert2DListToDataTable().DefaultView; }



The "ISBN-Nr." column is complete empty
rn_image_picker_lib_temp_6d0ea201-5421-413d-9adf-042682654100.jpg
Was this page helpful?