Hi juli jul.
If the combobox is on a form, then InitializeComponent() will instantiate
the combobox to a new combobox, thus wiping out the settings you have given
it. To fix this, move the InitialiseComponent() line to above your code and
remove the line this.comboBox1=newComboBox(). You code should look like:
public OpenDatabase(DataSet ds_db)
{
InitializeComponent();
this.comboBox1.DataSource=ds_db.Tables[0];
this.comboBox1.DisplayMember = "name";
}
By the way, as far as I understand, InitialiseComponent() should only be
called in the form constructor.
HTH
Ron.
"juli jul" <ju******@yahoo.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...
Hello I want to add data to comboBox from a dataset and doing it this
way:
public OpenDatabase(DataSet ds_db)
{
this.comboBox1=new ComboBox();
this.comboBox1.DataSource=ds_db.Tables[0];
this.comboBox1.DisplayMember = "name";
InitializeComponent();
}
if I am erasing the line :this.comboBox1=new ComboBox()- I get an error
,if I leave it the combobox is empty . How to add the data to it?
Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!