CF ComboBox databinding bug?

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() ;
}
 
I

Ilya Tumanov [MS]

Thanks for reporting this problem. I was able to repro it and it's already
fixed in CF V2.

The workaround might be to use format/parse event handlers.
However, I would suggest you simply don't that as nullable key is a very
bad idea.
Consider switching to auto increment integer key.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
D

Darren

When do you mean it's a bad idea? I use GUID based keys since identity keys
suck particularly when using merge replication and dynamic partitioning.
I don't want to have a non null value as a place holder for having no data
(that's what null values are for)



"Ilya Tumanov [MS]" said:
Thanks for reporting this problem. I was able to repro it and it's already
fixed in CF V2.

The workaround might be to use format/parse event handlers.
However, I would suggest you simply don't that as nullable key is a very
bad idea.
Consider switching to auto increment integer key.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Darren" <[email protected]>
Subject: CF ComboBox databinding bug?
Date: Tue, 8 Mar 2005 14:57:09 -0800
Lines: 49
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
5.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72790
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

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() ;
}
 
I

Ilya Tumanov [MS]

There are two possibilities:

1. Data base generates the key. In that case value of the key is irrelevant
in a new row; it would be substituted with the real thing from the data
base by DataAdapter on update.
2. You generate the key. Don't wait till later to replace null with a real
key, generate the key and add it to the record before it's even inserted
into the table. Correctly set primary/foreign keys on the DataSet would
ensure it's unique.

Best regards,

Ilya


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Subject: Re: CF ComboBox databinding bug?
Date: Wed, 9 Mar 2005 15:20:39 -0800
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72894
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

When do you mean it's a bad idea? I use GUID based keys since identity keys
suck particularly when using merge replication and dynamic partitioning.
I don't want to have a non null value as a place holder for having no data
(that's what null values are for)



"Ilya Tumanov [MS]" said:
Thanks for reporting this problem. I was able to repro it and it's already
fixed in CF V2.

The workaround might be to use format/parse event handlers.
However, I would suggest you simply don't that as nullable key is a very
bad idea.
Consider switching to auto increment integer key.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Darren" <[email protected]>
Subject: CF ComboBox databinding bug?
Date: Tue, 8 Mar 2005 14:57:09 -0800
Lines: 49
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1 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() ;
}
 
D

Darren

I think you misunderstood. I don't write the new row in the lookup table to
the database.
The row is only added to the lookup table (DataTable) at runtime to allow
the selection of "not selected",
it never gets persisted.

Sorry if I didn't make that clear.

"Ilya Tumanov [MS]" said:
There are two possibilities:

1. Data base generates the key. In that case value of the key is irrelevant
in a new row; it would be substituted with the real thing from the data
base by DataAdapter on update.
2. You generate the key. Don't wait till later to replace null with a real
key, generate the key and add it to the record before it's even inserted
into the table. Correctly set primary/foreign keys on the DataSet would
ensure it's unique.

Best regards,

Ilya


This posting is provided "AS IS" with no warranties, and confers no rights.
Subject: Re: CF ComboBox databinding bug?
Date: Wed, 9 Mar 2005 15:20:39 -0800
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72894
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

When do you mean it's a bad idea? I use GUID based keys since identity keys
suck particularly when using merge replication and dynamic partitioning.
I don't want to have a non null value as a place holder for having no data
(that's what null values are for)



"Ilya Tumanov [MS]" said:
Thanks for reporting this problem. I was able to repro it and it's already
fixed in CF V2.

The workaround might be to use format/parse event handlers.
However, I would suggest you simply don't that as nullable key is a very
bad idea.
Consider switching to auto increment integer key.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Darren" <[email protected]>
Subject: CF ComboBox databinding bug?
Date: Tue, 8 Mar 2005 14:57:09 -0800
Lines: 49
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
want the
key
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() ;
}
 
I

Ilya Tumanov [MS]

As far as I understand, you're using lookup table as a collection of items
to choose from.
Whatever's chosen will be stored in the actual table, is that correct?
If yes, that means the value you have in a lookup table would go to the
actual table.
Which, as I understand, would be persisted, right?
So, why not put actual key to the look up table so it would go to the
actual table?

I've tried Parse event, too bad it won't work (because of the way data
binding convert types).
The workaround would be to use column of type Object instead of column of
type string for the ID column in the table:

table.Columns.Add( "id", typeof(object) );

That would eliminate the need for conversion and DBNull will be passed to
the row unconverted to string.
That change should not impose overhead for strings, but it's not advisable
for value types.

Another workaround would be hooking into SelectedIndexChanged event and
moving value to the table manually.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
<[email protected]>
Subject: Re: CF ComboBox databinding bug?
Date: Thu, 10 Mar 2005 08:34:22 -0800
Lines: 176
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72934
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I think you misunderstood. I don't write the new row in the lookup table to
the database.
The row is only added to the lookup table (DataTable) at runtime to allow
the selection of "not selected",
it never gets persisted.

Sorry if I didn't make that clear.

"Ilya Tumanov [MS]" said:
There are two possibilities:

1. Data base generates the key. In that case value of the key is irrelevant
in a new row; it would be substituted with the real thing from the data
base by DataAdapter on update.
2. You generate the key. Don't wait till later to replace null with a real
key, generate the key and add it to the record before it's even inserted
into the table. Correctly set primary/foreign keys on the DataSet would
ensure it's unique.

Best regards,

Ilya


This posting is provided "AS IS" with no warranties, and confers no rights.
Subject: Re: CF ComboBox databinding bug?
Date: Wed, 9 Mar 2005 15:20:39 -0800
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
identity
keys
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
5.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.compactframework:72790
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

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()
 
D

Darren

The key from the lookup table is stored in the parent table unless no value
is selected in which case a null is written to the parent.

Thanks for the info on using an object instead of a string. I'll give that
a go.



"Ilya Tumanov [MS]" said:
As far as I understand, you're using lookup table as a collection of items
to choose from.
Whatever's chosen will be stored in the actual table, is that correct?
If yes, that means the value you have in a lookup table would go to the
actual table.
Which, as I understand, would be persisted, right?
So, why not put actual key to the look up table so it would go to the
actual table?

I've tried Parse event, too bad it won't work (because of the way data
binding convert types).
The workaround would be to use column of type Object instead of column of
type string for the ID column in the table:

table.Columns.Add( "id", typeof(object) );

That would eliminate the need for conversion and DBNull will be passed to
the row unconverted to string.
That change should not impose overhead for strings, but it's not advisable
for value types.

Another workaround would be hooking into SelectedIndexChanged event and
moving value to the table manually.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.<[email protected]>
Subject: Re: CF ComboBox databinding bug?
Date: Thu, 10 Mar 2005 08:34:22 -0800
Lines: 176
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72934
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I think you misunderstood. I don't write the new row in the lookup
table
to
the database.
The row is only added to the lookup table (DataTable) at runtime to allow
the selection of "not selected",
it never gets persisted.

Sorry if I didn't make that clear.

"Ilya Tumanov [MS]" said:
There are two possibilities:

1. Data base generates the key. In that case value of the key is irrelevant
in a new row; it would be substituted with the real thing from the data
base by DataAdapter on update.
2. You generate the key. Don't wait till later to replace null with a real
key, generate the key and add it to the record before it's even inserted
into the table. Correctly set primary/foreign keys on the DataSet would
ensure it's unique.

Best regards,

Ilya


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Darren" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: CF ComboBox databinding bug?
Date: Wed, 9 Mar 2005 15:20:39 -0800
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
no
data a
very
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
5.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.compactframework:72790
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

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()
 
I

Ilya Tumanov [MS]

Have you considered more common approach with "Accept" and "Reject" buttons
instead?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: CF ComboBox databinding bug?
Date: Thu, 10 Mar 2005 15:34:14 -0800
Lines: 270
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP0
9.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:72979
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

The key from the lookup table is stored in the parent table unless no value
is selected in which case a null is written to the parent.

Thanks for the info on using an object instead of a string. I'll give that
a go.



"Ilya Tumanov [MS]" said:
As far as I understand, you're using lookup table as a collection of items
to choose from.
Whatever's chosen will be stored in the actual table, is that correct?
If yes, that means the value you have in a lookup table would go to the
actual table.
Which, as I understand, would be persisted, right?
So, why not put actual key to the look up table so it would go to the
actual table?

I've tried Parse event, too bad it won't work (because of the way data
binding convert types).
The workaround would be to use column of type Object instead of column of
type string for the ID column in the table:

table.Columns.Add( "id", typeof(object) );

That would eliminate the need for conversion and DBNull will be passed to
the row unconverted to string.
That change should not impose overhead for strings, but it's not advisable
for value types.

Another workaround would be hooking into SelectedIndexChanged event and
moving value to the table manually.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.<[email protected]>
Subject: Re: CF ComboBox databinding bug?
Date: Thu, 10 Mar 2005 08:34:22 -0800
Lines: 176
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h70-66-178-253.sbm.shawcable.net 70.66.178.253
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
table a
real
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1 is
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1 table.
pocket
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()
;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top