Click here to Skip to main content
14,970,251 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Comments
   
We don't know what's the code of your program; never saw it. Does it even exist? :-)
—SA
Member 10200452 9-Aug-13 21:59pm
   
i respect Sir,,

For Each i As ListViewItem In LIST2.SelectedItems
LIST2.Items.Remove(i)
Next
Do While (ListBox1.SelectedItems.Count > 0)
ListBox1.Items.Remove(ListBox1.SelectedItem)
Loop
when i remove my selected listview Item it will Also remove in Listbox item
   
Very good, and where is the problem?
—SA
Member 10200452 9-Aug-13 22:27pm
   
the problem is if the user select item on listview and i have a button delete and when the user click the delete button will delete the listview and also the listbox because the button add or enter is i set to add it to the listbox to have my summary of name..
   
???
Mr.TMG 9-Aug-13 22:17pm
   
May I ask why you would choose to use a listView as well as a ListBox? Is that not redundant?
It seems like you are doubling the amount of work.
Member 10200452 9-Aug-13 22:31pm
   
i know its redundant but?,how can i compare using .contains in listview if the listview have the same input
so i used If ListBox1.Items.Contains(NAME2.Text) Then cause when i declare like this
If ListView1.Items.Contains(NAME2.Text) Then it will have an error.. how to it?..
Mr.TMG 9-Aug-13 23:46pm
   
you cannot compare using .contains, as the items in listview are not Sting, they are ListviewItem. i will post an example of how to cycle through the list view items to compare the text of each item to a string.
Mr.TMG 9-Aug-13 23:57pm
   
I just realized that you are also the author of this thread http://www.codeproject.com/Questions/634917/how-to-add-with-the-same-name-in-listview-and-will

I posted the same solution on there only it shows the full form.
I tried the code out in that second solution and it works. The fact that listview did not work directly with strings is something that did not occur to me during the first post.and the second post accounts for that fact.

1 solution

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")


VB
''' <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
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900