Jef*_*ady 1 c# listview winforms
我的应用程序读取文本文件并填充ListView.这很简单,像这样:
Date | Invoice | Status
20121015 | 123123 |
20121015 | 123124 |
20121015 | 123456 |
20121015 | 124123 |
Run Code Online (Sandbox Code Playgroud)
然后,我需要读取第二个文本文件,该文件可能包含也可能不包含在ListView中找到的发票以及状态.如果存在匹配的发票,则需要将该第二个文本文件的状态添加到ListView中,使其如下所示:
Date | Invoice | Status
20121015 | 123123 |
20121015 | 123124 |
20121015 | 123456 | Paid
20121015 | 124123 |
Run Code Online (Sandbox Code Playgroud)
最初我有一个只有发票号码的ListBox,并且正在做
int index = ListBox1.FindString(<whatever>);
Run Code Online (Sandbox Code Playgroud)
获取包含发票的行的索引,然后删除项目(RemoveAt(索引))并插入新项目,如
ListBox.Items.Insert(index, invoice + " PAID")
Run Code Online (Sandbox Code Playgroud)
如何使用ListView执行类似操作?我喜欢有列而不只是1行文本的想法.我应该使用ListView以外的东西来实现这一目标吗?
平均而言,我正在阅读的每个文本文件都有<1000行需要添加.
您可以枚举Items列表视图的集合.是的listview是理想的控制.
foreach (ListViewItem item in listView1.Items)
{
var invoice = item.SubItems[1];
if (invoice.Text == "whatever")
{
item.SubItems[2] = new ListViewItem.ListViewSubItem() { Text = "Paid" };
break;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6326 次 |
| 最近记录: |