473,670 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox index values

Hi there,

I would like to display the values of the index as chosen by the user in a
listbox. These values would be as per the datavaluefield. On testing I get
a value of -1:

Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
Me.Label1.Text = ListBox1.Items. Item(2).Text
End Sub

I would like to replace the "2" with the item the user selects. Any help
appreciated.
Nov 19 '05 #1
6 2650
hi,
you can get the selected value of the listbox at the server side using
ListBox1.Select edItem.Value .
so try using Me.Label1.Text = ListBox1.Select edItem.Value
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Hi there,

I would like to display the values of the index as chosen by the user in a
listbox. These values would be as per the datavaluefield. On testing I get
a value of -1:

Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
Me.Label1.Text = ListBox1.Items. Item(2).Text
End Sub

I would like to replace the "2" with the item the user selects. Any help
appreciated.

Nov 19 '05 #2
Thanks but I get an error:

Object reference not set to an instance of an object.
"srini" wrote:
hi,
you can get the selected value of the listbox at the server side using
ListBox1.Select edItem.Value .
so try using Me.Label1.Text = ListBox1.Select edItem.Value
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Hi there,

I would like to display the values of the index as chosen by the user in a
listbox. These values would be as per the datavaluefield. On testing I get
a value of -1:

Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
Me.Label1.Text = ListBox1.Items. Item(2).Text
End Sub

I would like to replace the "2" with the item the user selects. Any help
appreciated.

Nov 19 '05 #3
hi niggy,
are you binding the listbox at runtime? if so check that the listbox has
items after postback.. you are getting this error probably becoz the listbox
has no selected item.i think you are binding the listbox on postback.
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Thanks but I get an error:

Object reference not set to an instance of an object.
"srini" wrote:
hi,
you can get the selected value of the listbox at the server side using
ListBox1.Select edItem.Value .
so try using Me.Label1.Text = ListBox1.Select edItem.Value
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Hi there,

I would like to display the values of the index as chosen by the user in a
listbox. These values would be as per the datavaluefield. On testing I get
a value of -1:

Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
Me.Label1.Text = ListBox1.Items. Item(2).Text
End Sub

I would like to replace the "2" with the item the user selects. Any help
appreciated.

Nov 19 '05 #4
I have autopostback=tr ue and listbox1.databi nd() on page load. What now?

"srini" wrote:
hi niggy,
are you binding the listbox at runtime? if so check that the listbox has
items after postback.. you are getting this error probably becoz the listbox
has no selected item.i think you are binding the listbox on postback.
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Thanks but I get an error:

Object reference not set to an instance of an object.
"srini" wrote:
hi,
you can get the selected value of the listbox at the server side using
ListBox1.Select edItem.Value .
so try using Me.Label1.Text = ListBox1.Select edItem.Value
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:

> Hi there,
>
> I would like to display the values of the index as chosen by the user in a
> listbox. These values would be as per the datavaluefield. On testing I get
> a value of -1:
>
> Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
> ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
> Me.Label1.Text = ListBox1.Items. Item(2).Text
> End Sub
>
> I would like to replace the "2" with the item the user selects. Any help
> appreciated.
>
>

Nov 19 '05 #5
in the page load check for postback like
If Not Page.IsPostBack Then
--
code for binding the list box here
--
End If
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
I have autopostback=tr ue and listbox1.databi nd() on page load. What now?

"srini" wrote:
hi niggy,
are you binding the listbox at runtime? if so check that the listbox has
items after postback.. you are getting this error probably becoz the listbox
has no selected item.i think you are binding the listbox on postback.
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
Thanks but I get an error:

Object reference not set to an instance of an object.
"srini" wrote:

> hi,
> you can get the selected value of the listbox at the server side using
> ListBox1.Select edItem.Value .
> so try using Me.Label1.Text = ListBox1.Select edItem.Value
> --
> The best
> srini
> http://www.expertszone.com
>
>
> "Niggy" wrote:
>
> > Hi there,
> >
> > I would like to display the values of the index as chosen by the user in a
> > listbox. These values would be as per the datavaluefield. On testing I get
> > a value of -1:
> >
> > Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
> > ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
> > Me.Label1.Text = ListBox1.Items. Item(2).Text
> > End Sub
> >
> > I would like to replace the "2" with the item the user selects. Any help
> > appreciated.
> >
> >

Nov 19 '05 #6
Brilliant! Thanks.

"srini" wrote:
in the page load check for postback like
If Not Page.IsPostBack Then
--
code for binding the list box here
--
End If
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:
I have autopostback=tr ue and listbox1.databi nd() on page load. What now?

"srini" wrote:
hi niggy,
are you binding the listbox at runtime? if so check that the listbox has
items after postback.. you are getting this error probably becoz the listbox
has no selected item.i think you are binding the listbox on postback.
--
The best
srini
http://www.expertszone.com
"Niggy" wrote:

> Thanks but I get an error:
>
> Object reference not set to an instance of an object.
>
>
> "srini" wrote:
>
> > hi,
> > you can get the selected value of the listbox at the server side using
> > ListBox1.Select edItem.Value .
> > so try using Me.Label1.Text = ListBox1.Select edItem.Value
> > --
> > The best
> > srini
> > http://www.expertszone.com
> >
> >
> > "Niggy" wrote:
> >
> > > Hi there,
> > >
> > > I would like to display the values of the index as chosen by the user in a
> > > listbox. These values would be as per the datavaluefield. On testing I get
> > > a value of -1:
> > >
> > > Private Sub ListBox1_Select edIndexChanged( ByVal sender As System.Object,
> > > ByVal e As System.EventArg s) Handles ListBox1.Select edIndexChanged
> > > Me.Label1.Text = ListBox1.Items. Item(2).Text
> > > End Sub
> > >
> > > I would like to replace the "2" with the item the user selects. Any help
> > > appreciated.
> > >
> > >

Nov 19 '05 #7

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

Similar topics

1
7888
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the last item:- Specified argument was out of the range of valid values. Parameter name: '64' is not a valid value for 'Value'. The 64 reduces depending on how many listbox items are displayed.
1
8383
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...
3
19075
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
2911
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
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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...
0
7419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5684
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
4211
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
2800
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
1794
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.