7 Replies - 2098 Views - Last Post: 01 November 2012 - 07:52 PM Rate Topic: -----

#1 newforvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

listbox highlight all items as you type in vb.net

Posted 09 October 2012 - 02:24 PM

Hi guys i need really help cuz i'm new and still learning vb.net programming.
I think you do not need ask me what i need exactly cuz all says title.
I hope someone will know how to solve this problem for my project which i can't find out how to fix the problem i have only this small peace of code which does a bit of my work but do not hightlight items as i type from textbox.

Here is:

This one find extact items in listbox when i type but it does not hightlight them only add to listbox1 items extact as it found.

While ListBox1.FindStringExact(TextBox1.Text) <> -1
ListBox1.Items.Remove("")
End While


And this one find extact items as i type from textbox but do not hightlight them too.

For Each Itm As String In ListBox1.Items
If Itm.Contains(TextBox1.Text) Then
ListBox2.Items.Add(Itm)
End If
Next


how do i fix this problem and hightlight all matching found items in listbox as i type from textbox ?
Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: listbox highlight all items as you type in vb.net

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9044
  • View blog
  • Posts: 33,951
  • Joined: 12-June 08

Re: listbox highlight all items as you type in vb.net

Posted 09 October 2012 - 02:28 PM

It depends on a bajillion things. Where are these chunks of code found? What's running them? What does "highlight" mean? Where's the focus... set back color.. etc?
Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: listbox highlight all items as you type in vb.net

Posted 09 October 2012 - 10:20 PM

View Postnewforvb, on 09 October 2012 - 02:24 PM, said:

While ListBox1.FindStringExact(TextBox1.Text) <> -1
ListBox1.Items.Remove("")
End While



ListBox1.FindStringExact returns a value, which you never use except to decide whether to keep searching the ListBox.
ListBox1.Items.Remove("") will remove blank lines from the ListBox. If you want to use Remove, and to remove all instances of the string you found, youcould change to the following:
    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
        Dim idx As Integer = ListBox1.FindStringExact(TextBox1.Text)
        While idx > -1
            ListBox1.Items.Remove(TextBox1.Text)
            idx = ListBox1.FindStringExact(TextBox1.Text)
        End While
    End Sub



Quote

And this one find extact items as i type from textbox but do not hightlight them too.

For Each Itm As String In ListBox1.Items
If Itm.Contains(TextBox1.Text) Then
ListBox2.Items.Add(Itm)
End If
Next


how do i fix this problem and hightlight all matching found items in listbox as i type from textbox ?


How do you want to highlight them? It looks like you are only trying to add them to ListBox 2.
Was This Post Helpful? 0
  • +
  • -

#4 newforvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: listbox highlight all items as you type in vb.net

Posted 10 October 2012 - 01:35 AM

No i do not wanna remove anything just highlight words live as i type like so and add to listbox.
If it is possible.

Posted Image
Was This Post Helpful? 0
  • +
  • -

#5 newforvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: listbox highlight all items as you type in vb.net

Posted 10 October 2012 - 03:45 AM

Ok i found out how to highlight but now i have another problem with copy multiple selected items from listbox.

Can you fix it ?

Cuz it selects to clipboard only one item not all selected.

Here is the code.

Clipboard.SetText(ListBox1.SelectedItem.ToString(), TextDataFormat.Text)


And this one copy too only one item and save to txt to c:\ drive

Dim w As New IO.StreamWriter("c:\cool.txt", True)
w.WriteLine(ListBox1.SelectedItem, True)
w.Close()


how can i copy just selected items ?
Was This Post Helpful? 0
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: listbox highlight all items as you type in vb.net

Posted 10 October 2012 - 04:58 AM

You'll have to use ListBoxSelectedItems, and iterate through the collection (notice the difference SelectedItem vs SelectedItems).
Was This Post Helpful? 0
  • +
  • -

#7 newforvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: listbox highlight all items as you type in vb.net

Posted 10 October 2012 - 05:44 AM

Ok thanks i will try it
Was This Post Helpful? 0
  • +
  • -

#8 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: listbox highlight all items as you type in vb.net

Posted 01 November 2012 - 07:52 PM

View Postnewforvb, on 10 October 2012 - 02:35 AM, said:

No i do not wanna remove anything just highlight words live as i type like so and add to listbox.
If it is possible.

Posted Image

Are you fixated on using a ListBox? If you could use a RichTextBox, it becomes quite easy to highlight any text at all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1