Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 25th, 2004, 05:08 AM
Registered User
 
Join Date: Mar 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get selected Item from Listbox?

Hi there,

I have a form with a listbox that is assigned to a dataset.

In this listbox are Company-Names and I want to choose a company as the "active" company. Now I have two questions:

1. Is it possible to DISPLAY the Company-Names but to return the CustID if something is selected?

2. How do I access the return value? I've tried it the "standard-way" as with a simple listbox that is NOT connected to a DataSet, but I can't get a correct value...

Thanks in advance for your help :o)

Kind reagrds,
Michael
Reply With Quote
  #2 (permalink)  
Old March 25th, 2004, 06:33 AM
Registered User
 
Join Date: Nov 2003
Location: bhubaneswar, orissa, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to basant Send a message via MSN to basant Send a message via Yahoo to basant
Default

Hi Michael,
here i suggest the solution please try it .

set
        ListBox1.DataSource = dt
        ListBox1.DataTextField = "COMPANY_NAME"
        ListBox1.DataValueField = "CUSTID"


to access the value from listbox

val=ListBox1.SelectedItem.Value

if u have set selection mode property to multiple
then access it through for loop as

For i = 0 To ListBox1.Items.Count - 1
    If ListBox1.Items(i).Selected = True Then
        val= ListBox1.Items(i).Value
    End If
Next

hope u ll get the your solution.
Regds
Basant

s/w engg
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 GridView Selected Item stoverje BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2 2 August 8th, 2008 03:11 PM
How to get selected item from listview? try.test.abc C# 1 January 4th, 2007 02:34 AM
How Refer to Selected Item in DataGrid Morfoman General .NET 0 September 20th, 2005 11:41 AM
re: DataGrid Selected Item from outside grid vids ASP.NET 1.x and 2.0 Application Design 1 May 2nd, 2005 04:12 PM
Datagrid - Scroll to selected item rodmcleay ASP.NET 1.0 and 1.1 Professional 2 February 21st, 2005 08:36 PM



All times are GMT -4. The time now is 05:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.