ListView到ListBox项目 [英] ListView to ListBox Item

查看:82
本文介绍了ListView到ListBox项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人帮助我完成我的计划



它是这样的:



i有一个Listview当我在列表视图中添加项目时,列表框中的输入按钮也会在列表视图中添加项目,并且还会在列表框中添加



例如:我将Goerge输入列表视图并且添加按钮会自动在ListBox中添加项目Listview,因此List视图和ListBox将具有相同的项目..



问题是:如果我删除所选项目listview它会删除,但它没有删除ListBox中的相同项目..我的程序的代码是什么?



请帮助..在VB.net

解决方案

使用此功能:

只需将LV更改为列表框的名称

然后,如果是列表框包含一个带有指定文本的项目,只需拨打电话



LVContains(Some String)





 '''  <   summary  >  
''' 循环遍历列表视图中的每个项目,将text属性与TXT
''' < / summary >
''' < param name =TXT > 要检查的文本< / param >
''' < 返回 > 如果在listview中找到匹配的文本,则为true < / returns >
''' < 备注 > < /备注 >
私有 功能 LVContainsText(TXT As String As Boolean
' 准备从函数返回的结果
' 默认情况下将其设置为false以简化此过程
Dim 结果 As Boolean = False

< span class =code-comment>' 遍历listView中的项目列表以检查其属性
彼此独立
对于 每个作为 ListViewItem LV.Items
' 测试以查看文本属性是否匹配
如果 I.Text = TXT 那么
' 如果它匹配则它已经在列表中
result = True
结束 如果
下一步

' 返回结果
返回结果
结束 功能


an anyone help me in my program

it goes like this:

i have an Listview And Listbox when i add item in my listview the enter button will also add the item in listview and will add also in listbox

for example: i enter Goerge into the listview and add button will automatically add the item Listview in ListBox so List view and ListBox will have the same Item..

the question is: if i remove the item selected in listview it will remove,but it didnt remove the same item in ListBox.. what are the code of my program?

please Help.. in VB.net

解决方案

With this function:
Just change the LV to the name of your listbox
Then, to se if the list box contains an item with the specified text simply make the call

LVContains("Some String")


''' <summary>
  ''' Cycles through each item in list view to compare the text property to the TXT
  ''' </summary>
  ''' <param name="TXT">The text to check for</param>
  ''' <returns>true if matching text is found in listview</returns>
  ''' <remarks></remarks>
  Private Function LVContainsText(TXT As String) As Boolean
      'prepare a result to return from the function
      'setting it to false by default to simplify this process
      Dim result As Boolean = False

      'cycle through the list of items in listView in order to check it's properties
      'idividual of each other
      For Each I As ListViewItem In LV.Items
          'test to see it the text property matches
          If I.Text = TXT Then
              'if it does match then it's already in the list
              result = True
          End If
      Next

      'return the result
      Return result
  End Function


这篇关于ListView到ListBox项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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