Connecting Tech Pros Worldwide Forums | Help | Site Map

Brand new to C# VS 2003 programming, combobox problem!

Newbie
 
Join Date: Sep 2006
Posts: 3
#1: Sep 20 '06
I have a combobox on my form. It is attached to a dataset and uses the values from datetimepicker's in the where clause. When the form opens, everything is retrieved correctly. When I change the value of the datetimepicker I want to empty the combobox and retrieve the new values. I set my datasource to null, and clear the items which works fine, but I am never able to set the datasource back to the combobox even though I specify it, my combobox is empty. My dataset has the data, I can see that in the debugger.

Code in Value_Changed event looks like the following, I really hope someone can help:

PO_ComboBox.DataSource = null;
PO_ComboBox.Items.Clear();

this.po_da.SelectCommand = new System.Data.OleDb.OleDbCommand(@"SELECT DISTINCT RelatedKey FROM ContainerHeader WHERE (CreateDate BETWEEN '" + dateTimePicker1.Value.ToShortDateString() + "' AND '" + dateTimePicker2.Value.ToShortDateString() + "') ORDER BY RelatedKey", oleDbConnection1);

PO_ComboBox_Fill_DataSet();

THE FUNCTION CALLED LOOKS LIKE THE FOLLOWING:

private void PO_ComboBox_Fill_DataSet()
{

try
{
this.oleDbConnection1.Open();
po_da.Fill(po_ds, "ContainerHeader");
}
}
catch (System.Exception fillException)
{
throw fillException;
}
finally
{
this.oleDbConnection1.Close();
}

PO_ComboBox.DisplayMember = "RelatedKey";
PO_ComboBox.ValueMember = PO_ComboBox.DisplayMember;
PO_ComboBox.DataSource = po_ds.Tables["ContainerHeader"];

Newbie
 
Join Date: Sep 2006
Posts: 3
#2: Sep 20 '06

re: Brand new to C# VS 2003 programming, combobox problem!


I figured out my own problem, DON'T set the datasource to null to clear the combobox, clear the dataset insead. Well, there's two days of my life I'm never going to get back!
Reply