D
Darren
I have a combobox databound to a foreign key in a lookup table. I want to
manually add a row to the lookup table that has a DBNull value as the key so
I can select a null foreign key. This works well in the full framework but
on the compact framework when I select the null value from the dropdown, the
databinding changes the FK to a blank string when it should be a
DBNull.Value
here is the code snippet. You'll need to add a combobox and a button to the
form. When you select the "null" value from the dropdown and click the
button you get different results between the desktop and pocket pc versions.
Is this a bug? Any ideas for a workaround?
private void Form1_Load(object sender, System.EventArgs e)
{
lookupTable = new DataTable();
lookupTable.Columns.Add( "id", typeof(string) );
lookupTable.Columns.Add( "desc", typeof(string) );
lookupTable.Rows.Add( new object[] { DBNull.Value, "null" } );
lookupTable.Rows.Add( new object[] { "a", "OK" } );
table = new DataTable();
table.Columns.Add( "id", typeof(string) );
table.Columns.Add( "fk", typeof(string) );
DataRow r = null ;
r = table.NewRow();
r.ItemArray = new object[] { "1", "a" };
table.Rows.Add( r );
comboBox1.DataBindings.Add( "SelectedValue", table, "id" );
comboBox1.DataSource = lookupTable ;
comboBox1.DisplayMember = "desc" ;
comboBox1.ValueMember = "id" ;
BindingContext
.Position = 0 ;
}
private void button1_Click(object sender, System.EventArgs e)
{
table.Rows[0].EndEdit();
button1.Text = table.Rows[0]["id"].GetType().ToString() ;
}
manually add a row to the lookup table that has a DBNull value as the key so
I can select a null foreign key. This works well in the full framework but
on the compact framework when I select the null value from the dropdown, the
databinding changes the FK to a blank string when it should be a
DBNull.Value
here is the code snippet. You'll need to add a combobox and a button to the
form. When you select the "null" value from the dropdown and click the
button you get different results between the desktop and pocket pc versions.
Is this a bug? Any ideas for a workaround?
private void Form1_Load(object sender, System.EventArgs e)
{
lookupTable = new DataTable();
lookupTable.Columns.Add( "id", typeof(string) );
lookupTable.Columns.Add( "desc", typeof(string) );
lookupTable.Rows.Add( new object[] { DBNull.Value, "null" } );
lookupTable.Rows.Add( new object[] { "a", "OK" } );
table = new DataTable();
table.Columns.Add( "id", typeof(string) );
table.Columns.Add( "fk", typeof(string) );
DataRow r = null ;
r = table.NewRow();
r.ItemArray = new object[] { "1", "a" };
table.Rows.Add( r );
comboBox1.DataBindings.Add( "SelectedValue", table, "id" );
comboBox1.DataSource = lookupTable ;
comboBox1.DisplayMember = "desc" ;
comboBox1.ValueMember = "id" ;
BindingContext
}
private void button1_Click(object sender, System.EventArgs e)
{
table.Rows[0].EndEdit();
button1.Text = table.Rows[0]["id"].GetType().ToString() ;
}