13 Replies - 3808 Views - Last Post: 30 October 2009 - 07:51 AM Rate Topic: -----

#1 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Remove Custom Listbox Item

Posted 29 October 2009 - 08:21 PM

How do I remove custom items for example

ListBox
---------
Text1
Text2
Hi
Ho
Text3
Text4
Gimme
So
Tutorial
TextBox5


And I want to remove all except items that has the word "Text" in it.
Is This A Good Question/Topic? 0
  • +

Replies To: Remove Custom Listbox Item

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Remove Custom Listbox Item

Posted 29 October 2009 - 08:57 PM

loop over the items in the listbox and if the item text ListBox.items(x).Contains("Text"), then don't remove it, but start from the LAST item and work back to the first or things won't work the way you expect!

loop over the items in the listbox and if the item text ListBox.items(x).Contains("Text"), then don't remove it, but start from the LAST item and work back to the first or things won't work the way you expect!
Was This Post Helpful? 0
  • +
  • -

#3 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 29 October 2009 - 09:03 PM

So it would be something like this?

If ListBOx1.Items(25).Contains("Text") Then



So what next?
Was This Post Helpful? 0
  • +
  • -

#4 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 01:11 AM

Try here:
http://www.dreaminco...topic134863.htm
Was This Post Helpful? 0
  • +
  • -

#5 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 05:01 AM

That link didn't help me at all. Let say I have a listbox, a textbox, and a button.

For the listbox, it'll have the following:

Mac
Pizza1
Zelda
Pizza2
Text
Hotdog
Pizza3

Then I would type something inside the text box for example ("Pizza")
So when I click the button, it will find the word "Pizza" in it and it will copy that to another listbox.
Was This Post Helpful? 0
  • +
  • -

#6 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 05:34 AM

In case you guys still don't get it, here what I'm trying to do

 Try
			If (WebBrowser1.Document IsNot Nothing) Then
				With WebBrowser1.Document
					For Each Items As HtmlElement In WebBrowser1.document.Links
						ListBox1.Items.Add(Items.GetAttribute("HREF").ToString())
					Next
				End With
			End If
		Catch ex As Exception
		End Try



Ok It will get all the links and what I want it to do is when I click Button2, it will get all the links that has the word "dream" in it (as for example) and move it to another listbox.
Was This Post Helpful? 0
  • +
  • -

#7 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 05:41 AM

This is an section of the link that I suggested which is exactly what you are talking about:

3. Find an item in the list box.
I will now perform a search of the list box for a value inputted into the text box. In the following code, notice :
For intIndex As Integer = 0 To myListBox.Items.Count – 1
I will iterate throught the list box items by index number. The first step is to create a variable that will hold the Index number. The index will start at “0” and count up to “1 less than” the number of items in the box. This is important to remember:
Index starts at 0;
Count starts at 1;
So the highest index number can only be 1 less than the Count
Code for the Search:
Private Sub Search()
	'Retreive string from textBox
	Dim strSearch As String = myTextBox.Text
	'If no text is in the textbox, do nothing
	If strSearch Is Nothing Then Exit Sub
	'Declare a Indexing Variable to iterate 
	'through the list box items.
	For intIndex As Integer = 0 To myListBox.Items.Count - 1
		If strSearch = myListBox.Items.Item(intIndex) Then
			myListBox.SelectedIndex = intIndex
		End If
Next
End Sub



intIndex will be the index of the Item you have searched for, in the first listbox.
Get that item (by index number "intIndex") and add it to the other listbox.

The sample program in that link has...................
A listbox, a text box and a button, It does averything that you are speaking of except adding the item to another listbox
ListBox2.Items.Add(ListBox1.Items.Item(intIndex))


Was This Post Helpful? 0
  • +
  • -

#8 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 05:47 AM

Well this code works

		'Retreive string from textBox
		Dim strSearch As String = TextBox1.Text
		'If no text is in the textbox, do nothing
		For intIndex As Integer = 0 To ListBox1.Items.Count - 1
			If strSearch = ListBox1.Items.Item(intIndex) Then
				ListBox1.SelectedIndex = intIndex
				ListBox2.Items.Add(ListBox1.Items.Item(intIndex))
			End If
		Next


But I want it to select all that has the word ".php" and add to ListBox2
Was This Post Helpful? 0
  • +
  • -

#9 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 06:14 AM

Try the InStr Function:
http://msdn.microsof...44c(VS.85).aspx
Was This Post Helpful? 0
  • +
  • -

#10 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 06:27 AM

Ok now I'm seriously lost with InStr Function.
Was This Post Helpful? 0
  • +
  • -

#11 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 07:19 AM

Ok I'm so bad at explaining what I'm trying to do but I think I know how to explain.
When I click Button2, it will look for text in the listbox1 that has the word "Text" in it and add to ListBox2.
Was This Post Helpful? 0
  • +
  • -

#12 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 07:32 AM

Hi,

the instr function return a position where it found the string, so if its bigger than 0 it found it in the string....

Here is what you can do

 Dim x As Integer
		For x = 0 To ListBox1.Items.Count - 1
			If InStr(ListBox1.Items(x), "Text") > 0 Then
				ListBox2.Items.Add(ListBox1.Items(x))
				'To remove it, use this
				'ListBox1.Items.RemoveAt(x)
				Exit For
			End If
		Next


Was This Post Helpful? 0
  • +
  • -

#13 koolazngy94  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 119
  • Joined: 29-July 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 07:45 AM

Thanks motcom but now how do I make it keep doing that until there's no more?
Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,418
  • Joined: 29-May 08

Re: Remove Custom Listbox Item

Posted 30 October 2009 - 07:51 AM

I know this might sound dumb but why don't you do check the when you add then the item to the list?
It save you the trouble of removing it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1