-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: NullableString in Nullables
PostPosted: Mon May 16, 2005 6:00 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
why don't implement NullableString in Nullables ??

need that for correct data binding


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 8:00 am 
Beginner
Beginner

Joined: Thu May 12, 2005 3:41 am
Posts: 24
Location: London, UK
What's the problem with using System.String?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 11:19 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
when I binding a string with a textbox
Code:
tbOT.DataBindings.Add(new Binding("Text",pedido,"OT"));


and this string is null ocurrs an error at runtime: 'System.OutOfMemoryException'

searching in the web, I found a "betterbinding" function that resolves that problem:


Code:
      public class BetterBinding : Binding
      {
         public BetterBinding(string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember)
         {
         }

         protected override void OnParse(ConvertEventArgs e)
         {
            TypeConverter converter = TypeDescriptor.GetConverter(e.DesiredType);

            if (converter != null && converter.CanConvertFrom(e.Value.GetType()))
            {
               e.Value = converter.ConvertFrom(e.Value);
            }
            else
            {
               base.OnParse(e);
            }
         }
      }

....
....

tbOT.DataBindings.Add(new BetterBinding("Text",pedido,"OT"));


I think that changing "System.String" by "NullableString" the problem is solved or not???.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 4:12 am 
Beginner
Beginner

Joined: Thu May 12, 2005 3:41 am
Posts: 24
Location: London, UK
I have created an issue on JIRA for this.

The obvious behaviour would be for a NullableString to return a value of String.Empty for a null. This could cause problems in the GUI, as you would probably want to distinguish between an uninitialised string and an empty string. You could use "<null>", but that may be a valid value in some circumstances.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 4:36 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NullableString should just return DBNull.Value if it's null, shouldn't it? All controls can handle DBNulls just fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 8:27 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
Actually it's the other way around. when binding to a text box the string CAN'T be null. It's not a nullable type because it is already nullable as it is a reference type not a value type. I have a custom type i use to translate nulls in the data as empty strings (and the other way aroung).

I just posted this class to the JIRA issue. I also set all strings to string.Empty in thier initializers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.