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 CSVMVVM_ { /// <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
No description
5 Replies
EinfachNurBaum
EinfachNurBaumOP10mo ago
The csv file is correct
Sir Rufo
Sir Rufo10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Sir Rufo
Sir Rufo10mo ago
$codegif
Want results from more Discord servers?
Add your server