I am trying to bind multiple comboboxes here to the same datasource.
I see a strange behaviour with reference to the time when the ComboBox
actually gets its Items Collection populated.

I am putting my Code in here. 2 functions (implementing the same
functionality) which give me variable results.

To give an idea what i am trying to achieve:
I am developing a new Container Control (extending Panel)(i call it
DataWindow) which supports a Grid as well as Free-Form layout.

//----------- MY CODE--------------//

// This Works Correctly
// Gets called for the Free-Form as well as Grid Layout
protected virtual void e_ComboBoxRetrieved()
{

// dwComboControl is a Class that stores information about
// a single ComboBox Control placed on the DataWindow
dwComboControl dwc;

// icol_ComboControls is a custom collection of dwComboControl.
// Thus a collection of all the ComboControlsthat the developer
// may have placed on the DataWindow
int i_ComboCount = this.icol_ComboControls.Count;

ComboBox cb;
DataTable dt;
for(int i = 0; i < i_ComboCount; i++)
{
dwc = this.icol_ComboControls[i];
dt = DataUtil.GetDataTable(dwc.ComboSql);

// if the layout is FreeForm, then bind the ComboBox
if(this.dwLayout == dwLayoutType.FreeForm)
{
cb = dwc.ControlRef;
cb.DataSource = dt;
cb.DisplayMember = dwc.ComboDisplayCol;
cb.ValueMember = dwc.ComboDataCol;

// I Get the correct result of here.
// ie. cb.Items.Count == dt.Rows.Count
MessageBox.Show(cb.Name + " : " + cb.Items.Count.ToString() +
" Rows : " + dt.Rows.Count.ToString() );


}
else // Do not bind the ComboBox, just set the
// reference of the retrieved DataTable to
// dwComboControl's idt (instance DataTable)
{
dwc.idt = dt;
}
}
}

// Gets Called for Each Row retrieved in the Grid
// I have used reflection here and replicated the controls
// placed by the Developer during Design-Time into a new
// Panel which is passed as a reference here.
private void f_BindComboBox(dwDetailPanel adp)
{
ComboBox cb;
dwComboControl dwc;

// ie. for each ComboBox actually placed by the Developer
// for a Single Row
int i_ComboCount = this.icol_ComboControls.Count;
for(int i = 0; i < i_ComboCount; i++)
{
dwc = this.icol_ComboControls[i];

// Get a Copy of DataTable to which this ComboBox is to
// be Bound. Doing this to save Database trips for
// binding ComboBox's for each row.
// dwc.idt has been populated earlier in e_ComboBoxRetrieved()
DataTable dt = dwc.idt.Copy();

// Get the Instance of ComboBox in the Current Panel
cb = (ComboBox)adp.icol_ChildControls.GetControl(dwc.Name);

// icol_ChildControls is a custom Collection (with a
// HashTable implementaion). It is a collection of All
// the controls placed on the Detail Panel

cb.DataSource = dt;
cb.DisplayMember = dwc.ComboDisplayCol;
cb.ValueMember = dwc.ComboDataCol;

// This is where i see inconsistent behaviour
// ie. cb.Items.Count is 0
// dt.Rows.Count gives a correct Figure.
MessageBox.Show(cb.Name + " : " + cb.Items.Count.ToString() + "
Rows : " + dt.Rows.Count.ToString() );

}
}

//----------------------------------------------------------------//


Further more, when my DataWindow (Grid) finally gets displayed, I find
that all the ComboBox's in all the Rows retrieved do display the Bound
Data correctly.

The problem for me is, after each DetailPanel is created for each row
retrieved for the Grid DataWindow, I have to set the
ComboBox.SelectedValue to the value in the DataBase. When i go to do
that, i find out that there are no Items in the ComboBox.

This is how the events have been organised in my Control

For Each DataRow
1) Create Host DetailPanel for the Row
2) Replicate all the ChildControls for the Row (using reflection)
3) Bind ComboBox's on the new DetailPanel
4) Set values of the Current Row in the DetailPanel

End For

I have double checked that these two functions are the only place
where anything related to ComboBox is happening in my application.

Anyone who is aware of such problems / has any idea why is this
happening / any solution. Help is appreciated.

-Snehal