เพิ่มรายการ (---โปรดเลือก---) ลงในกล่องคำสั่งผสมที่มีแหล่งข้อมูล

ฉันมีกล่องคำสั่งผสมพร้อมแหล่งข้อมูลแต่ฉันต้องการเพิ่มรายการ

ฉันอยากให้มันเป็นแบบนี้

----Please select one---     //the item I want to add 
Tokyo                        //the items that came from the database
Osaka                        //the items that came from the database
Boston                       //the items that came from the database
Manila                       //the items that came from the database

ฉันจะแก้ไขปัญหานี้ได้อย่างไร?

ขอบคุณ


person Daniel Barga    schedule 01.12.2013    source แหล่งที่มา
comment
แหล่งข้อมูลที่แน่นอนของ Combobox ของคุณคืออะไร DataTable? หรืออย่างอื่น?   -  person King King    schedule 01.12.2013
comment
แหล่งข้อมูลเป็นขั้นตอนการจัดเก็บ   -  person Daniel Barga    schedule 01.12.2013
comment
นั่นไม่ใช่แหล่งข้อมูลจริง แหล่งข้อมูลที่นี่ควรเป็นคอลเลกชัน .NET, รายการ, ..., stored Procedure ของคุณเพิ่งถูกเรียกผ่าน ADO.NET เพื่อดึงข้อมูล   -  person King King    schedule 01.12.2013
comment
แล้วฉันต้องทำอย่างไร? ฉันจะระบุแหล่งข้อมูลที่แน่นอนได้อย่างไร   -  person Daniel Barga    schedule 01.12.2013
comment
คุณกำหนดอะไรให้กับ ComboBox.DataSource?   -  person King King    schedule 01.12.2013
comment
@DanielBarga: โปรดแชร์รหัสของคุณโดยที่คุณผูก DataSource กับ comboBox   -  person Sudhakar Tillapudi    schedule 01.12.2013
comment
มันมาจากชุดข้อมูล แหล่งข้อมูล: teleTechInventoryDataSet สมาชิกข้อมูล: m_Department_comboSite //stored Procedure   -  person Daniel Barga    schedule 01.12.2013
comment
@SudhakarTillapudi ฉันจะรับรหัสนั้นซึ่งฉันผูกกับ ComboBox ได้ที่ไหน ขออภัย ฉันไม่ใช่มืออาชีพ :)   -  person Daniel Barga    schedule 01.12.2013
comment
@DanielBarga: แสดงรหัสของคุณ   -  person Sudhakar Tillapudi    schedule 01.12.2013


คำตอบ (2)


คุณต้องเพิ่ม "โปรดเลือก" ให้กับคอลเลกชันที่คุณเชื่อมโยงก่อนที่จะตั้งค่าแหล่งข้อมูล เช่น...

var countries = GetCountriesFromDatabase(); // Get countries from the database

countries.Insert(0, "----Please select one---"); // Insert your please select item

Combobox1.DataSource = countries; // Assign the datasource after inserting the item
person rrrr    schedule 11.08.2017

person    schedule
comment
ฉันไม่คิดว่าสิ่งนี้ถูกต้อง - คุณจะได้รับ ArgumentException หากคุณลอง โดยมีข้อความ Items collection can be modified when the DataSource property is set. - person Jon; 31.12.2013