GridViewCheckBoxColumn binding to a short

3 posts, 0 answers
  1. Timo
    Timo avatar
    1 posts
    Member since:
    Aug 2010

    Posted 24 Aug 2010 Link to this post

    Hello, I'm trying to bind a short datatype to a GridViewCheckBoxColumn but I'm getting a cast error.
    I know if I bind to a bool datatype works ok so How can I bind a GridViewCheckBoxColumn to a short datatype assumming that 0=false/unchecked and 1=true/checked?

    Thx
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Aug 2010 Link to this post

    Hello Timo,

    You can add a class implementing the IValueConverter Interface that would be responsible for transforming the short datatype to boolean value. For example, your custom converter may look similar to:

    class ShortToBooleanConverter : IValueConverter
    {
             
        public object Convert(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
      {
            var myValue = (short)value;
            if (myValue == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
         }
     
       public object ConvertBack(object value, Type targetType,
                object parameter, System.Globalization.CultureInfo culture)
         {
            return null;
       }
    }


    Then the definition of your GridViewCheckBoxColumn may be as follows;
    <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding MyShortValue,    
                            Converter={StaticResource ShortToBooleanConverter}}"
    />

     

    Greetings,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Sharique
    Sharique avatar
    2 posts
    Member since:
    Feb 2012

    Posted 21 Sep 2012 Link to this post

    Hi maya 

    its worked  for me  ... thanks a lot  . it is as exactly as i was looking for ....

Back to Top