473,382 Members | 1,717 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,382 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 3053
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.