473,769 Members | 6,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

listbox index

Man the help in VB.NET is hard to use!!

Can somebody please tell me the syntax to find the index value a user has
chosen from a list of items in a listbox. Also, is there a way to use the
string value instead of the index number?

I'm trying to do something like...

if lstBox.items.in dex = 0 then
stuff...
end if

OR

if lstBox.items.in dex = "California " then
stuff...
end if

--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog: http://sprayberry.typepad.com/ciaccio

Jun 27 '08 #1
3 7013
On Jun 27, 8:22 pm, "Jeff Ciaccio" <non...@noreply .orgwrote:
Man the help in VB.NET is hard to use!!

Can somebody please tell me the syntax to find the index value a user has
chosen from a list of items in a listbox. Also, is there a way to use the
string value instead of the index number?

I'm trying to do something like...

if lstBox.items.in dex = 0 then
stuff...
end if

OR

if lstBox.items.in dex = "California " then
stuff...
end if

--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog:http://sprayberry.typepad.com/ciaccio
As i understood, you need to get "selected" index and item:

For index value you need "lstBox.Selecte dItems" :

' -----------------------------------

f lstBox.Selected Index = 0 then
' stuff...
end if

' ---------------------------------
To get Selected Item you need "lstBox.Selecte dItem" :

' --------------------------------

if lstBox.Selected Item = "California " then
stuff...
end if

' -----------------------

Thanks,

Onur Güzel
Jun 27 '08 #2
On Jun 27, 8:36 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
On Jun 27, 8:22 pm, "Jeff Ciaccio" <non...@noreply .orgwrote:
Man the help in VB.NET is hard to use!!
Can somebody please tell me the syntax to find the index value a user has
chosen from a list of items in a listbox. Also, is there a way to use the
string value instead of the index number?
I'm trying to do something like...
if lstBox.items.in dex = 0 then
stuff...
end if
OR
if lstBox.items.in dex = "California " then
stuff...
end if
--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog:http://sprayberry.typepad.com/ciaccio

As i understood, you need to get "selected" index and item:

For index value you need "lstBox.Selecte dItems" :

' -----------------------------------

f lstBox.Selected Index = 0 then
' stuff...
end if

' ---------------------------------

To get Selected Item you need "lstBox.Selecte dItem" :

' --------------------------------

if lstBox.Selected Item = "California " then
stuff...
end if

' -----------------------

Thanks,

Onur Güzel
Sorry correcting first line of my post:

For index value you need "lstBox.Selecte dIndex" :

' -----------------------------------

f lstBox.Selected Index = 0 then
' stuff...
end if

' ........

Thanks,

Onur Güzel
Jun 27 '08 #3
That did it - thanks!!
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3426
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows graphically the change: e.g. if I remove an element from the ArrayList object, then that element should not be no more displayed in the list box. Actually i'm using this code below:
1
2893
by: Patty O'Dors | last post by:
Hi I have some code to create an ownerdrawn listbox (derived), and when I add an item to it, the bold text of the first item (the title, 'Collections and Maturities') mysteriously seems to get bunched up at the right, i.e. squashed up! any idea why? The main bit of the code is as such // (in progressReporter.cs) protected struct LBRow //a row of the listbox, whether it be the title or a
1
8421
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
4
11497
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at multiple examples and they all do it this way. What's wrong? (variables are also being set to the values...
8
2357
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the event. I do have EnableViewState = True for the listbox. I'm imagining (wanting) to populate the listbox named: lstNames by using the DataValueField from lstDepartments. It's quite apparent though that the event is not triggering as I can misname...
11
1807
by: John Dann | last post by:
I'm still struggling to find a way of reordering the items within the same single listbox with drag and drop. I think I've got the drag working but it's the drop code I can't figure out. What I have currently is (with the listbox set to AllowDrop): Sub MyListBox_MouseDown(args etc...) DoDragDrop(MyListBox.SelectedItem, DragDropEffects.Move) End Sub Sub MyListBox_DragEnter(args etc...)
3
19082
by: Mitch | last post by:
Is the following a correct representation of the relationship of the selected index to selected item: INDEX ITEM 0 "item 1" 1 "item 2" 2 "item 3" and so on. I keep getting the same string for selected index 0 and 1; i.e. both are "item 1". I'm new to C# and not exactly an accomplished programmer. Any suggestions?
2
2915
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
3
4299
by: Kevin Walzer | last post by:
I'm trying to set the active item in a Tkinter listbox to my application's currently-defined default font. Here's how I get the fonts loaded into the listbox: self.fonts=list(tkFont.families()) self.fonts.sort() for item in self.fonts: self.fontlist.insert(END, item) #self.fontlist is the
7
5619
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client browser the list box scroll position is at the top.
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.