Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 November 8th, 2007, 05:34 AM
Authorized User
 
Join Date: Oct 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get SelectedValue of Control

Hi,

How do I return the value of a control that a user clicked on?

How do I get the SelectedValue?? or the SelectedItem?


Only seem able to get the Text value. But I have databinded Controls and I want to get the SelectedValue.

My code so far...

Code:
BlockControl control = (Control)sender;
ControlSelected = control.Name;
PersonSelected = control.Text;
How do I do this?

Thanks again.
 
Old November 8th, 2007, 09:38 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Does your control either inherit from a control that exposes the SelectedValue (the dropdown list for example) or does it implement its own versions of SelectedValue?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 8th, 2007, 09:44 AM
Authorized User
 
Join Date: Oct 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does your control either inherit from a control that exposes the SelectedValue (the dropdown list for example) or does it implement its own versions of SelectedValue?

Yes I want it to inherit from a DropDownList.

Here's my code...
Code:
private void myListBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Control control = (Control)sender;
                ControlSelected = control.Name;
                ItemSelected = control.Text;
            }
        }
 
Old November 8th, 2007, 12:17 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Why doesn't the following work?

DropDown control = (DropDown)sender;
control.SelectedValue;

or even just

myListBox.SelectedValue;

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectedValue which is invalid--it does not exists cesemj ASP.NET 2.0 Basics 2 October 26th, 2007 10:29 AM
Problems with "SelectedValue" in Control Parameter rsearing ASP.NET 2.0 Basics 5 July 11th, 2007 09:30 AM
Need Help with DropDownList SelectedValue putputty ASP.NET 2.0 Basics 4 June 27th, 2007 11:44 AM
SelectedValue property using SqlDataReader shiju ADO.NET 0 September 28th, 2003 03:27 AM
comboBox.SelectedValue melvik C# 1 August 19th, 2003 09:21 AM





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