VB.NET ListView在第一行插入项目。 [英] VB.NET ListView Insert item in first row.
本文介绍了VB.NET ListView在第一行插入项目。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个从ftp服务器下载文件的程序。
将所有下载的文件和下载文件放在ListView中。
我想优先考虑下载文件所以我想在第一个索引中添加项目。
我尝试使用这个示例代码但它不起作用。
I'm creating a program that downloads file from ftp server.
Putting all downloaded files and downloading files in a ListView.
I want to prioritize the downloading file so I want to add the item in first index.
I try using this sample code but it doesn't work.
'FIRST DOWNLOAD
With lstDownload.Items.Add("Sample", 0)
.SubItems.Add(2)
.SubItems.Add(3)
.SubItems.Add(4)
.SubItems.Add(5)
.SubItems.Add(6)
.SubItems.Add(listDownload.Count - 1)
End With
'SECOND DOWNLOAD
With lstDownload.Items.Add("Sample1", 0)
.SubItems.Add(2)
.SubItems.Add(3)
.SubItems.Add(4)
.SubItems.Add(5)
.SubItems.Add(6)
.SubItems.Add(listDownload.Count - 1)
End With
在该示例中,我想首先在ListView中显示Sample1。
任何人都可以向thi发布代码/建议s。
感谢先进...完全赞赏
In that example I want to display the "Sample1" first in the ListView.
Can anyone post a code/suggestion to this.
Thanks in advanced... totally appreciated
推荐答案
你好,
解决方案是使用Insert而不是Add。
Hello,
A solution is to use Insert instead of Add.
'FIRST DOWNLOAD
With lstDownload.Items.Add("Sample", 0)
.SubItems.Add(2)
.SubItems.Add(3)
.SubItems.Add(4)
.SubItems.Add(5)
.SubItems.Add(6)
.SubItems.Add(listDownload.Count - 1)
End With
'SECOND DOWNLOAD
With lstDownload.Items.Insert(0, "Sample1", 0)
.SubItems.Add(2)
.SubItems.Add(3)
.SubItems.Add(4)
.SubItems.Add(5)
.SubItems.Add(6)
.SubItems.Add(listDownload.Count - 1)
End With
Valery
Valery
你可以试试像
you could try something like
Dim listDownloads as New List(of ListViewItem)
Dim lvItem as ListViewItem
lvitem = New ListViewItem()
lvitem.text = "Sample"
lvitem.subitems.add(2)
lvitem.subitems.add(3)
lvitem.subitems.add(4)
lvitem.subitems.add(5)
lvitem.subitems.add(6)
'Set your colour and stuff here
'lvitem.backcolor
listDownloads.add( lvitem ) 'Add the item to an array
'Now add the items to the listview
Dim iCount as integer
For iCount = yourlistview.items.count -1 to 0 step -1
yourlistview.items.add( lvitem )
Next
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
ListViewItem lvi = new ListViewItem("Add "+DateTime.Now);
ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = DateTime.Now.ToString();
lvi.SubItems.Add(lvsi);
_list.Insert(0, lvi);
listView1.Invalidate();
}
这篇关于VB.NET ListView在第一行插入项目。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文