c# - How to Display a combobox message -


i'm looking or advice. trying put message in combo box prompting user make selection. thing i've read has told use this.comboboxname.text = "message",

however have tried in few different places , dose not seem work in code.

i'm wondering if have missed blatantly obvious. suggestions?

code:

namespace databaseconnection {   public partial class mainwindow : window   {     public mainwindow()     {         initializecomponent();         //this dosen't work         this.worldcbx.text = "select country";         sqlconnection con = new sqlconnection(@"data source=>this works fine.mdf;integrated security=true;connect timeout=30");         con.open();         sqlcommand com = new sqlcommand("select name bbc", con);         sqldatareader sdr = com.executereader();         while (sdr.read())         {             this.worldcbx.items.add(sdr["name"]);         }         sdr.close();     }     private void worldcbx_selectionchanged(object sender, selectionchangedeventargs e)     {         //this dosen't work either.           this.worldcbx.text = "select country";     } } 

}

the combobox.text = “select country” set selection of combobox “select country” if exist in items list. if have combobox items are…

select country

usa

russia

canada

mexico

then command combobox.text = “select country” set combobox’s selected value “select country” because item in combobox's items. combobox act describe… use code below.

however, problem approach once select country, combobox return “select country.” user may forget selected or may not sure. either way, user standpoint can confusing.

it sounds simple label "select country" above combobox better solution. hope helps.

combobox1.items.add("select country"); (int = 1; < 15; i++) {   combobox1.items.add("country_" + i); } combobox1.selectedindex = 0;  private void combobox1_selectedindexchanged(object sender, eventargs e) {   // selected index   // - reset combobox "select country   this.combobox1.selectedindexchanged -= new system.eventhandler(this.combobox1_selectedindexchanged);   combobox1.text = "select country";   this.combobox1.selectedindexchanged += new system.eventhandler(this.combobox1_selectedindexchanged); } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -