Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 April 20th, 2008, 05:52 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add Item in a Binded Combo Box

Hello Frnds,
            I am currently woking on windows form programming(C#).I am having a combo box which has a binded dataset.Now my problem is, I want to add a "--Select--" option at index 0 of combo box.How to do it?

Please please help me.



 
Old April 20th, 2008, 12:22 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

I dont think you can do this if the data is bound to a DataSet, I think you would need to load the items for the list and then manually add them to the list, obviously adding the "select" item first.

Rob
http://robzyc.spaces.live.com
 
Old April 21st, 2008, 08:45 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not positive that this will work in a windows forms app, but here's how we do it in ASP.NET:

myControl.DataSource = myDataSet;
myControl.DataBind(); // <-- This isn't required in win forms.
myControl.Items.InsertAt(0, "-- Select --");

You should be able to do something similar in a winforms combo box.

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
pre-selecting an item in a combo box kscase Visual Basic 2005 Basics 1 July 12th, 2007 07:33 AM
add drop down / combo box for selection mamuco Classic ASP Components 0 May 30th, 2007 06:34 PM
Combo Box item from SQLDataadpter... to Datagrid venkikrao VB.NET 0 April 19th, 2006 08:57 PM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM





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