Selected Item in a listbox in vb.net

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2251 Views - Last Post: 22 July 2012 - 05:11 PM Rate Topic: -----

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Selected Item in a listbox in vb.net

Posted 22 July 2012 - 01:27 PM

I have a textbox and a listbox on a form
As I write in textbox the item matching to the text of textbox is hilighted in the listbox

If I have 100 Items in the listbox and if there are 15 items starting with "S"
Now if I write "S" in the textbox then it hilights the first item starting with "S"
Upto this point it works fine

But the problem is that I can See just the first item starting with "S"
and if i want to see the other items starting with "S" then I have to scroll down
I want to see all the items starting with "S"

In short I want the items from "A" to "R" should go up and it should be visible if I scroll to them
and First Item starting with "S" should be visibly first item in the listbox

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Selected Item in a listbox in vb.net

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 02:49 PM

1. set SelectionMode property to MultiSimple
2. show your code
Was This Post Helpful? 0
  • +
  • -

#3 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:08 PM

I dont want to select multiple
I just want to see multiple
I dont have any code for that

I attach the two screenshots below to help understand my problem

The first image shows what i have and second image shows what i want

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by Vishal1419: 22 July 2012 - 03:13 PM

Was This Post Helpful? 0
  • +
  • -

#4 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:13 PM

I don't see attachments
Was This Post Helpful? 0
  • +
  • -

#5 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:21 PM

I was editing my post
So you might have not seen the images
Now you can see that
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:45 PM

so you want to first item starting with "s" to be displayed as first item in the list?
Was This Post Helpful? 0
  • +
  • -

#7 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:51 PM

yes, now you got the point

but i dont want it to be the first item in the list
I want to scroll the list to the first item as in image 2
the user must just see that as first item but actually it should not be the first item
for more information see the scrollbar of listbox in both the images
Was This Post Helpful? 0
  • +
  • -

#8 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 03:56 PM

You can do a little trick. Lets say you have 10 items displayed in the list, and you want to select item number 40 as first. Y
Was This Post Helpful? 0
  • +
  • -

#9 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:01 PM

What you want to say?????????
I dont understand :whistling:
Was This Post Helpful? 0
  • +
  • -

#10 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:09 PM

You can do a little trick. Lets say you have 10 items displayed in the list and you want to select item number 40. First you will select item number 50 then item number 40.
Dim DIC As Integer = 10 ' displayed items count

'select item number 40
Dim SelItem As Integer = 40
Listbox1.SelectedIndex = SelItem + DIC
Listbox1.SelectedIndex = SelItem

This is not tested, but you can try.

You can also use ListView. ListView has method EnsureVisible that might help.

Datagridview has property "FirstDisplayedScrollingRowIndex", this is what you looking for.
Was This Post Helpful? 0
  • +
  • -

#11 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:28 PM

Thanks Sela,

You are right, But I Call all the codings for lstbox and textbox from a module
And In more than 200 forms I use the listbox
All of Different Size
And I cant replace it with a DataGridView or ListView
Also I cant Write codings for all the listboxes
Was This Post Helpful? 0
  • +
  • -

#12 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:35 PM

Quote

And In more than 200 forms I use the listbox
200+?? :)

Quote

And I cant replace it with a DataGridView or ListView
Also I cant Write codings for all the listboxes

Then how you plan to achieve this?
Was This Post Helpful? 0
  • +
  • -

#13 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:39 PM

By Just Changing some Codings in the module :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#14 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 04:52 PM

If you already use the same code (module) for all listboxes, then you can easy adapt the sample I have posted, where is the problem?
Was This Post Helpful? 0
  • +
  • -

#15 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Selected Item in a listbox in vb.net

Posted 22 July 2012 - 05:03 PM

The size of all listbox is different, so I cant say How many Items are visible at a time
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2