473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

ListBox Problem

I am trying to take the item the user selected in a list box and put it in a
string variable. When I execute the code
RegionalName = lstRegional.Items(lstRegional.SelectedIndex)
I get this error:
Additional information: Cast from type 'DataRowView' to type 'String' is not
valid.

The listbox is bound to a dataset so I suspect that is part of the problem.
How can I "take" the selection and put it into a variable?
--
------------------------------------
Wayne Wengert
wa***@wengert.org
Jul 19 '05 #1
1 3055
The key thing to remember in .NET is that combo and list
boxes do not store simple values, they store types. So
what you've done in this situation is you've bound a
dataset or a datatable to the listbox. You've set it up
to display one value by setting the DisplayMember
property. At this point you can do two things:
1. Set the ValueMember property (and use the
Listbox.SelectedValue property to retrieve the
information which returns a discreet value) or
2. Perform a ctype on the selected item to convert it to
a datarow and then extract the value you want.

Option 2 is more flexible, but Option 1 is a faster
operation.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"
-----Original Message-----
I am trying to take the item the user selected in a list box and put it in astring variable. When I execute the code
RegionalName = lstRegional.Items (lstRegional.SelectedIndex)

I get this error:
Additional information: Cast from type 'DataRowView' to type 'String' is notvalid.

The listbox is bound to a dataset so I suspect that is part of the problem.How can I "take" the selection and put it into a variable?--
------------------------------------
Wayne Wengert
wa***@wengert.org
.

Jul 19 '05 #2

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

Similar topics

5
by: Coz | last post by:
Hi all, I'm looking for help again!!! I have been writing a page to update a database but now have another 'silly' problem with listbox's...Grrr... I'm trying to populate the list box with...
2
by: mathieu cupryk | last post by:
I have problems with listboxes in the webform2.cs, the textboxes are working well when I do a click on next. I am missing something. It works with the textboxes. Here is the file: using System;...
0
by: amber | last post by:
Hello, I'm having problems with a listbox... I have a listbox that is populated when a user presses a button (retrieve). There is a textbox on the form, and if the textbox is left blank, and...
4
by: amber | last post by:
Hello I'm not sure if I should give up trying to find an answer here...or just keep posting my problem.. I'm having problems with a listbox.. I have a listbox that is populated when a user...
6
by: Glen Wolinsky | last post by:
I have two virtually identical listbox controls on a tabPage in my application. I bind a small datatable to each one when a new project (my data) is selected from a treeview control (this works...
2
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
1
by: faheem ramzan via .NET 247 | last post by:
I have a problem using listbox. I used to put items in listbox dynamically and maintained size automatically in listbox sothat there is no scroll bar in the listbox. I have a problem when the...
2
by: Ben Collver | last post by:
I am using Darwin 10.4.9, tcl 8.4.7, tk 8.4, and python 2.3.5. I have also tried Python 2.5 on Darwin, Debian, and Fedora Core 6. I am working on a GUI front-end to a Python program of mine. It...
2
by: Rotsey | last post by:
Hi, I have a Listbox in a Panel of SplitContainer. I want to anchor it so the listbox grows/shrinks vertically with the resizing the splitcontainer. This is my code What happens is it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.