Как загрузить данные в правильные столбцы представления таблицы данных
Привет Ребята,
I am loading data from a Treeview (i.e. user clicks node) and a TextBox (i.e. user copies text using button click) and auto-generating number column and Date and Time column data (See Image). This data is passed to a Listview which can be altered by the user. Then, the user saves the data from Listview to a text file. Then, the data is loaded from the text file and displayed in a DataGridView so the user can manipulate the data (i.e. Filtering, etc.). However, as you can see from the image, the first 8 rows in the DGV load correctly without inserting a text Snippet in the Snippet column. But, when I load the data with a Snippet, the Date and Time data is added to a new/separate row underneath the added row. I have been trying for many hours searching on Google and debugging, etc., with no success? I include (what I think are) relevant code snippets here and hope someone can help me to resolve this problem? I am grateful for any help! :-) (Sorry, I wanted to upload an image to show the problem, but I guess that's not possible here?). The DGV columns are in the following order: Number Column = 0 (#); Mapping Column = 1; Snippet Column = 2; Date and Time column = 3.
Что я уже пробовал:
'DGV SETUP: 'Create an unbound DataGridView by declaring a column count. DataGridView7.ColumnCount = 4 DataGridView7.ColumnHeadersVisible = True ' Set the column header style. Dim columnHeaderStyle As New DataGridViewCellStyle() columnHeaderStyle.BackColor = Color.Beige columnHeaderStyle.Font = New Font("Verdana", 10, FontStyle.Bold) DataGridView7.ColumnHeadersDefaultCellStyle = columnHeaderStyle 'Creates columns and sets column header names. DataGridView7.Columns(0).Name = "#" DataGridView7.Columns(1).Name = "Mapping Items" DataGridView7.Columns(2).Name = "Snippet" DataGridView7.Columns(3).Name = "Date and Time" With DataGridView7 ' .AutoResizeColumnHeadersHeight .Columns("#").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader .Columns("Mapping Items").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Snippet").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Date and Time").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill End With 'SAVE LISTVIEW TO A SPECIFIC FILE: ' Creates a <CSV> File Using csv As New System.IO.StreamWriter("C:\Users\CurrentUser\Documents\MappingData.txt", True) 'What does True do here??? For Each Item As ListViewItem In ListView1.Items csv.WriteLine(String.Format("{0};{1};{2};{3}", Item.SubItems(0).Text, Item.SubItems(1).Text, Item.SubItems(2).Text, Item.SubItems(3).Text)) Next End Using 'FORM LOAD EVENT: LOAD MAPPING DGV FROM TEXT FILE: Private Sub LOADDGV() Using stream As System.IO.FileStream = System.IO.File.OpenRead("C:\Users\CurrentUser\Documents\MappingData.txt") Using reader As New System.IO.StreamReader(stream) Dim line As String = reader.ReadLine() While (line IsNot Nothing) Dim columns = line.Split(";") 'Text separator which splits to display in DGV columns (i.e. ;:," ", etc.) line = reader.ReadLine() Dim index = DataGridView7.Rows.Add(line) DataGridView7.Rows(index).SetValues(columns) End While End Using End Using End Sub
Alek Massey
Что делает сгенерированный csv файл (MappingData.txt) смотрите, как в блокноте?
Member 13032047
Привет Алек, csv выглядит следующим образом, но я не могу найти никакой разницы между случайным текстом (например, пример 1), который загружается правильно, и другим текстом (например, пример 2)? Вот несколько примеров:
Пример 1: (Этот текст правильно загружается в столбцы DGV)
Том Круз никогда не будет играть Джеймса Бонда, но есть параллельная вселенная, в которой он в основном Феликс Лейтер, приятель 007 из ЦРУ, и теперь шесть фильмов глубоко в его собственной франшизе, все более похожей на Бонда.
1;картографический пункт - Кто мы?;Том Круз никогда не будет играть Джеймса Бонда, но есть параллельная вселенная, в которой он в основном Феликс Лейтер, приятель 007 из ЦРУ, а теперь еще шесть фильмов глубоко в его собственной франшизе, все более похожей на Бонда. ;Четверг, 26 Июля 2018 Года, 03:45
Пример 2: (Этот текст загружает столбец чисел(индекс 0; заголовок #), столбец сопоставления(индекс 1) и столбец фрагмента кода(индекс 2) все правильно, но дата и время вставляются в новую строку под столбцом сопоставления(индекс 1), а не в ту же строку, что и данные, загружаемые вместе с ним под столбцом даты и времени(индекс 3)
There is nothing like a program that really works. When you can advance in your work with the help of IT. The best thing about IT is that it is developing all the time! This morning, however, I found a problem in the program that only just found a partial solution to? I spent hours looking on the internet, but couldn't find anything that resolves the problem? The data is not being loaded into the correct DataGridView(DGV) columns? But, the partial answer I just found is that the text I was using is causing the problem?! When I used a random text from the internet, perhaps with less punctuation, the data is loaded correctly into the DGV columns?!
1;MAPPING ITEM - Who are we?;There is nothing like a program that really works. When you can advance in your work with the help of IT. The best thing about IT is that it is developing all the time! This morning, however, I found a problem in the program that I only just found a partial solution to? I spent hours looking on the internet, but couldn't find anything that resolves the problem? The data is not being loaded into the correct DataGridView(DGV) columns? But, the partial answer I just found is that the text I was using is causing the problem?! When I used a random text from the internet, perhaps with less punctuation, the data is loaded correctly into the DGV columns?! ;Thursday 26 July 2018, 04:04