Re: CF ComboBox databinding bug?

From: Ilya Tumanov [MS] (ilyatum_at_online.microsoft.com)
Date: 03/11/05


Date: Fri, 11 Mar 2005 01:29:53 GMT

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.
--------------------
> From: "Darren" <deo.is@unknown.com>
> References: <eDlw1HDJFHA.2604@TK2MSFTNGP15.phx.gbl>
<Cp617YOJFHA.1140@TK2MSFTNGXA02.phx.gbl>
<umNTo5PJFHA.3420@tk2msftngp13.phx.gbl>
<$QFINPQJFHA.3580@TK2MSFTNGXA02.phx.gbl>
<eFWzO7YJFHA.2884@tk2msftngp13.phx.gbl>
<R01ClacJFHA.132@TK2MSFTNGXA02.phx.gbl>
> 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: <#$Z$1lcJFHA.2852@TK2MSFTNGP09.phx.gbl>
> 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]"" <ilyatum@online.microsoft.com> wrote in message
> news:R01ClacJFHA.132@TK2MSFTNGXA02.phx.gbl...
> > 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.
> > --------------------
> > > From: "Darren" <deo.is@unknown.com>
> > > References: <eDlw1HDJFHA.2604@TK2MSFTNGP15.phx.gbl>
> > <Cp617YOJFHA.1140@TK2MSFTNGXA02.phx.gbl>
> > <umNTo5PJFHA.3420@tk2msftngp13.phx.gbl>
> > <$QFINPQJFHA.3580@TK2MSFTNGXA02.phx.gbl>
> > > 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: <eFWzO7YJFHA.2884@tk2msftngp13.phx.gbl>
> > > 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]"" <ilyatum@online.microsoft.com> wrote in message
> > > news:$QFINPQJFHA.3580@TK2MSFTNGXA02.phx.gbl...
> > > > 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" <deo.is@unknown.com>
> > > > > References: <eDlw1HDJFHA.2604@TK2MSFTNGP15.phx.gbl>
> > > > <Cp617YOJFHA.1140@TK2MSFTNGXA02.phx.gbl>
> > > > > 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: <umNTo5PJFHA.3420@tk2msftngp13.phx.gbl>
> > > > > 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]"" <ilyatum@online.microsoft.com> wrote in
> message
> > > > > news:Cp617YOJFHA.1140@TK2MSFTNGXA02.phx.gbl...
> > > > > > 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" <deo.is@unknown.com>
> > > > > > > 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: <eDlw1HDJFHA.2604@TK2MSFTNGP15.phx.gbl>
> > > > > > > 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[table].Position = 0 ;
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > private void button1_Click(object sender,
> System.EventArgs
> > > e)
> > > > > > > {
> > > > > > > table.Rows[0].EndEdit();
> > > > > > > button1.Text =
> > table.Rows[0]["id"].GetType().ToString()
> > > ;
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> >
>
>
>