Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 25th, 2004, 05:08 AM
Registered User
Join Date: Mar 2004
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,
Old March 25th, 2004, 06:33 AM
Registered User
Join Date: Nov 2003
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

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

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

to access the value from listbox


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

hope u ll get the your solution.

s/w engg

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.