-1
我有两个listview控件,每个都有相同的列标题。 Listview1包含主数据表,而listview2有一小部分数据,我需要将其添加到Listview1中的主数据中。我可以使用AddRange选项将此新数据添加到Listview1中主数据的底部,但我需要将它添加到Listview1中的数据顶部,但看不到如何。列表视图数据到另一个列表视图
如果有人能帮助,我将不胜感激。先谢谢你。
谢谢您的意见,我已采取了。
让我添加一些更多的细节和一些代码。 Listview2中的数据是我读入Listview2的每月csv文件输入。数据是一组详细信息,第一个字段是日期,最近一次是数据顶部的日期。我将这些数据打包为一个数组,并尝试加载到listview1(主文件)中,使用完全相同的字段和日期顺序。这里是我用来加载csv和将打包数据放入Listview1的代码的代码。唯一的问题是,它将数据放在Listview1中当前文件的末尾,所以它会失序,所以我试图将它放在Listview1中当前文件的顶部。
' load the file into listview with this quick routine.
Dim CSVTest As List(Of String) = New List(Of String)
CSVTest = File.ReadAllLines(ImportDirname).ToList
Dim ColNames As List(Of ColumnHeader) = New List(Of ColumnHeader)
Dim ColumnArray() As String = CSVTest(0).Split(",")
For i = 0 To ColumnArray.Count - 1
ColNames.Add(New ColumnHeader)
ColNames(i).Name = ColumnArray(i)
ColNames(i).Text = ColumnArray(i)
Next
ListView2.Columns.AddRange(ColNames.ToArray)
'This adds the rest of the data from the file to the listview.
For I = 1 To CSVTest.Count - 1
Dim col() As String = CSVTest(I).Split(",")
Dim NewLVItem As ListViewItem = New ListViewItem(col(0))
NewLVItem.Name = col(0)
For j = 1 To col.Count - 1
NewLVItem.SubItems.Add(col(j))
Next
ListView2.Items.Add(NewLVItem)
Next (I)
' this adds the range to the bottom of the listview data
' - not what is required. I need it at the top !!!!!
Dim Items(ListView2.Items.Count - 1) As ListViewItem
For i As Integer = 0 To ListView2.Items.Count - 1
Items(i) = CType(ListView2.Items(i).Clone, ListViewItem)
Next
ListView1.Items.AddRange(Items)
再次如果有人可以帮助,我将不胜感激。
你需要证明你自己的问题,一些努力。请阅读[问]并参加[导览]。预先感谢您 – Plutonix
[**'ListView.Items.Insert()'**](https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.insert(v = vs.110)的.aspx) –