Results 1 to 2 of 2

Thread: [RESOLVED] ComboBox runtime DataSource problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Resolved [RESOLVED] ComboBox runtime DataSource problem

    Hi all,
    I have a DataTable (named dt) with data inside. I need to create a runtime CheckBox and assign that DataTable as ComboBox.DataSource. Here's some C# code:
    Code:
    ComboBox cmb = new ComboBox();
    cmb.DisplayMember = "desc";
    cmb.ValueMember = "id";
    cmb.DataSource = dt;
    The VB equivalent is:
    Code:
    Dim cmb as New ComboBox()
    cmb.DisplayMember = "desc"
    cmb.ValueMember = "id"
    cmb.DataSource = dt
    With ComboBox drawn at design time (and without creating a new one) the code works fine. But if I don't use a design time ComboBox and create a new one from scratch (like the code above) doesn't work.
    I also tried to force the creation of the control by calling the .CreateControl() method or forcing the creation of the handle by getting it with (C#)
    Code:
    IntPtr p = ComboBox.Handle;
    The result is ALWAYS a ComboBox with ZERO Items.

    Any help is appreciated.

    Thanks,
    Xmas.
    Learn, this is the Keyword...

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Resolved Re: ComboBox runtime DataSource problem

    Found by myself. I needed to create a new BindingContext.
    Learn, this is the Keyword...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width