Мне нужен метод, чтобы пользователь мог добавить новый заголовок столбца в свой импортированный файл CSV в WPF (DataGrid) - PullRequest
0 голосов
/ 20 июня 2020

Простой код Xaml

<DataGrid AutoGenerateColumns="True"  ItemsSource="{Binding}" Grid.Column="1" Grid.Row="3" Margin="0,5,0,0" Height="325" Width="500" Grid.ColumnSpan="7"/>

Вот мой код CS

public class Cloths
        {
            public string Hauptartikelnr { get; set; }
            public string Artikelname { get; set; }
            public string Hersteller { get; set; }
            public string Beschreibung { get; set; }
            public string Materialangaben { get; set; }
            public string Geschlecht { get; set; }
            public string Produktart { get; set; }
            public string Aermel { get; set; }
            public string Bein { get; set; }
            public string Kragen { get; set; }
            public string Herstellung { get; set; }
            public string Taschenart { get; set; }
            public string Grammatur { get; set; }
            public string Material { get; set; }
            public string Ursprungsland { get; set; }
            public string Bildname { get; set; }
        }


        public static class CSVTable
        {
            public static List<Cloths> ReadFile(string filepath)
            {
                var lines = File.ReadAllLines(filepath);
                var data = new List<Cloths>();
                foreach (var line in lines.Skip(1))
                {
                    var split = line.Split(';');
                    var cloths = new Cloths();
                    if (split.Length != 16)
                    {
                        continue;
                    }
                    cloths.Hauptartikelnr = split[0];
                    cloths.Artikelname = split[1];
                    cloths.Hersteller = split[2];
                    cloths.Beschreibung = split[3];
                    cloths.Materialangaben = split[4];
                    cloths.Geschlecht = split[5];
                    cloths.Produktart = split[6];
                    cloths.Aermel = split[7];
                    cloths.Bein = split[8];
                    cloths.Kragen = split[9];
                    cloths.Herstellung = split[10];
                    cloths.Taschenart = split[11];
                    cloths.Grammatur = split[12];
                    cloths.Material = split[13];
                    cloths.Ursprungsland = split[14];
                    cloths.Bildname = split[15];
                    data.Add(cloths);
                }
                return data.ToList();
            }

Я подумал о решении и думаю, что кнопка ADD для добавления 1+ в массив будет хорошее решение, если я ошибаюсь, скажите мне, что я работаю с WPF в первый раз. ОТ: Если у кого-то есть хорошие знания о WPF, было бы неплохо, если бы он был возможен для DM, потому что у него есть много вопросов по этому поводу.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...