How to asynchronously populate combo box on a window form

Aug 17 2009 11:57 AM

Is it possible to populate a combo box after the form has loaded.  I've tried the following, the code runs; however, the combo box is empty.  What am I missing?
thanks!
namespace TRSWin.Inquiry
{
    public delegate TOutput MyAsyncMethod<TOutput>(ref ComboBox myComboBox, object dataSource);
    public partial class PositionInquiry : TRSWin.ParentForm
    {
        public PositionInquiry()
        {
            InitializeComponent();
        }

        public bool BindLookup(ref ComboBox myComboBox, object dataSource)
        {
            myComboBox.DataSource = dataSource;
            myComboBox.DisplayMember = "Description";
            return true;
        }
        public void BeginBindLookup(ref ComboBox myComboBox, object dataSource)
        {
            MyAsyncMethod<bool> method = BindLookup;
            method.BeginInvoke(ref myComboBox, dataSource, EndBindLookup, method);
        }
        public void EndBindLookup(IAsyncResult result)
        {
            MyAsyncMethod<bool> method = result.AsyncState as MyAsyncMethod<bool>;
            //bool b = method.EndInvoke(result);  // Can't figure out how to make this call either, so I will ignore for now.
        }
        private void PositionInquiry_Load(object sender, EventArgs e)
        {
            BindLookup(ref cboSymbol, Cache.SymbolLookup);  // Works, populates list
            BeginBindLookup(ref cboSymbol, Cache.SymbolLookup);  // Runs, but list is empty
           
        }
    }
}

Answers (1)