This is a migrated thread and some comments may be shown as answers.

GridViewCheckBoxColumn binding to a short

2 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Timo
Top achievements
Rank 1
Timo asked on 24 Aug 2010, 03:41 PM
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 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 25 Aug 2010, 09:56 AM
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
0
Sharique
Top achievements
Rank 1
answered on 21 Sep 2012, 05:47 AM
Hi maya 

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

Tags
GridView
Asked by
Timo
Top achievements
Rank 1
Answers by
Maya
Telerik team
Sharique
Top achievements
Rank 1
Share this question
or