Vb我想知道列表视图是否包含项目 [英] Vb I want to know if list view contain item

查看:68
本文介绍了Vb我想知道列表视图是否包含项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我列出了带有驱动器信息的视图

i创建一个带有计时器的按钮来刷新列表视图

i想创建一个if if if list list有什么东西什么都不做如果列表视图丢失了关闭应用程序的内容



i have i list view with drive info
i create a button with timer to refresh the list view
i want to create an if that if list view have something do nothing and if list view losing something close the application

Dim _itm As ListViewItem
 For Each _itm In ListView1.Items
                If (_itm.SubItems(0).Text).ToString.Equals("") Then
                    Exit For
                End If
                If Not (_itm.SubItems(0).Text).ToString.Equals("") Then
                    Me.Close()
                End If
            Next





我的尝试:





What I have tried:

Dim _itm As ListViewItem
 For Each _itm In ListView1.Items
                If (_itm.SubItems(0).Text).ToString.Equals("") Then
                    Exit For
                End If
                If Not (_itm.SubItems(0).Text).ToString.Equals("") Then
                    Me.Close()
                End If
            Next

推荐答案

你出错了。您将ListView视为应用程序数据的容器。不要陷入这个非常糟糕的习惯。



UI控件用于显示应用程序所持有的数据模型的直观表示。它们永远不应该用作数据模型。



不要检查ListView的数据。检查您所持有的数据,而不是您要查找的项目。



通过执行此操作,您可以将数据模型与UI分开,从而可以使用更多您的代码独立于您正在编写的应用程序类型,如Windows窗体,WPF,ASP.NET,Mobile,...
You're going about this wrong. You're treating the ListView as a container of your application data. DON'T get into this very bad habit.

UI controls are there to show a visual representation of the data model your application holds. They should never be used AS the data model.

Don't check a ListView for data. Check the data you hold instead for the item you're looking for.

By doing this, you separate your data model from the UI making it possible to use more of your code independent from the type of application you're writing such as Windows Forms, WPF, ASP.NET, Mobile, ...


这篇关于Vb我想知道列表视图是否包含项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆