Home All Groups Group Topic Archive Search About

ComboBox.DataSource = {DataView}; But after is still = Nothing

Author
12 Jan 2005 1:20 PM
Jon Brunson
I've got a very weird problem, when I run the following code the
ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a
UserControl in a Class Library. I'm using VS.NET 2003 with SourceSafe
6.0d (the problem occurs whether the code is checked in or out)

If I step through the code, The line

  Me.cmbInputDevice.DataSource = dv

Executes fine (ie, doesn't error), but on the next line (after an
F8/F11) Me.cmbInputDevice.DataSource is still equal to Nothing.

dv is definately not Nothing, and is definately not empty (I can view
it's contents in the Command Window)

*if* I delete the combo box from the control, and add a new one, give it
the same name, etc, it works for a while, but then goes back to
not-working after an unknown period. This isn't any kind of practical
solution.


Sql.GetDeviceTable() returns a valid & populated DataTable

[VB.NET] (Native Language)

    Dim dt As DataTable = Sql.GetDeviceTable()

    Dim dr As DataRow = dt.NewRow()
    dr("ID") = DBNull.Value
    dr("Description") = "<None>"
    dt.Rows.Add(dr)

    Dim dv As DataView = dt.DefaultView
    dv.Sort = "Description"
    dv.ApplyDefaultSort = True

    Me.cmbInputDevice.DataSource = dv
    Me.cmbInputDevice.DisplayMember = "Description"
    Me.cmbInputDevice.ValueMember = "ID"

[C#] (Translation)

    DataTable dt = Sql.GetDeviceTable();

    DataRow dr = dt.NewRow();
    dr("ID") = DBNull.Value;
    dr("Description") = "<None>";
    dt.Rows.Add(dr);

    DataView dv = dt.DefaultView;
    dv.Sort = "Description";
    dv.ApplyDefaultSort = True;

    this.cmbInputDevice.DataSource = dv;
    this.cmbInputDevice.DisplayMember = "Description";
    this.cmbInputDevice.ValueMember = "ID";

AddThis Social Bookmark Button