473,396 Members | 1,865 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,396 software developers and data experts.

Cast a control to ListBox/CheckBox/RadioBtnList in order to use a common property

Hello , i use a method that has a Control as parameter

ex. public static void Method(Control c)

This control can be RadioButtonList, DropDownList , CheckBoxList , ListBox ..All of these controls return a ListItemCollections collection

through the property .Items (ex. DropDownList1.Items in case of a dropdownlist)

I need to find a way to cast the control c (my parameter) to one of the above controls (or to a common interface they implenent) in order to use the Items property that returns a ListItemCollection ..

So what i m trying to do is :

ListItemCollection control_items = (( ------ )c).Items ..What should be in the brackets?



What i actually want is use the item.Text and item.Value properties for all the items found in the itemscollection of the above control (i dont care if its a dropdownlist or a radiobuttonlist , i just want the item.Text and item.Value

Thnx for your time..
Jun 12 '07 #1
2 3614
Found the solution , for everyone interested , all these controls inherit from ListControl class , so thats the class we should use to cast the "generic" control
Jun 13 '07 #2
Frinavale
9,735 Expert Mod 8TB
Found the solution , for everyone interested , all these controls inherit from ListControl class , so thats the class we should use to cast the "generic" control
Welcome to theScripts LetMeFly!

I'm glad you've found the solution to your problem, thanks for sharing it with us.

In the future could you please post your questions in the .NET Forums section instead of the .NET Articles section (blue menu along the top: Forums->.NET). The Articles section is reserved for "How-tos" and other tips to help people along.

Thanks a lot!
Enjoy yourself here on theScripts.

-Frinny
Jun 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
4
by: Derrick | last post by:
Hello all; I'm trying to simulate a "scrollable context menu". What I want is to have a listbox fill the entire area of a small form (with no border). Using the designer and property grid, I...
1
by: Emilio | last post by:
Hi, I have a user control with a datalist. Each datalistitem has a label which is databound, a hidden textbox which is databound, a textbox and a checkbox. like follows: <asp:datalist...
7
by: tom | last post by:
Hi, I want a listbox below a hidden calendar control. The problem is that the listbox will shadow the calendar when the calendar is visible. How can I bring the calendar from back to front? ...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState...
6
by: segue | last post by:
Hi; I need to change the order of a listbox array from a form app where I select order up or down. What's a good way to do that? Regards; Segue
7
by: schaefty | last post by:
I recently posted this on the incorrect forum, and so I would like to ask the question here. I did get some good ideas on the other group, but I have not yet come up with a solution for me. I am...
4
by: Lou O | last post by:
Is it possible to use the row (index) of a list box as control source Property for a text box? Example: Text1.ControlSource Property is set to "= List1.Column(0,2)" in design view. When I open...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.