RadNumUpdown IsEnabled binding

4 posts, 0 answers
  1. Gilbert van Veen
    Gilbert van Veen avatar
    68 posts
    Member since:
    Oct 2009

    Posted 17 Nov 2011 Link to this post

    Hello,

    I have a RadGridView with two important columns. In one column there is a RadNumUpDown control and in the other one a RadComboBox. See below.

    Is it possible to enable the RadNumUpdown "cell" only when the SelectedItem != 'x' from the RadComboBox. The prefered way is to do it trough XAML.

    The XAML is:
    <telerik:GridViewDataColumn Header="Value" Width="100" DataMemberBinding="{Binding HourValue, Mode=TwoWay}">
                                   <telerik:GridViewColumn.CellTemplate>
                                       <DataTemplate>
                                           <telerik:RadNumericUpDown ValueFormat="Numeric" CustomUnit="%" NumberDecimalDigits="2" Value="{Binding Value, Mode=TwoWay}" Minimum="1" Maximum="100" SmallChange="1" IsEnabled="{Binding ElementName=TypeComboBox, Path=SelectedIndex, Mode=OneWay} ????????"/>
                                       </DataTemplate>
                                   </telerik:GridViewColumn.CellTemplate>
                               </telerik:GridViewDataColumn>
                                 
                               <telerik:GridViewDataColumn Header="Type" Width="150">
                                   <telerik:GridViewColumn.CellTemplate>
                                       <DataTemplate>
                                           <telerik:RadComboBox Name="TypeComboBox" DisplayMemberPath="TypeDescription" SelectedValuePath="TypeId" SelectedValue="{Binding HourType, Mode=TwoWay}" ItemsSource="{Binding CategoryTypes, Source={StaticResource CategoryTypeList}}" />
                                       </DataTemplate>
                                   </telerik:GridViewColumn.CellTemplate>
                               </telerik:GridViewDataColumn>
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Nov 2011 Link to this post

    Hi Gilbert Van Veen,

    I recommend to bind the IsEnabled property of the numericUpDown  control  to the HourType using an IValueConverter.

    Inside the convert method of your converter you may perform the check for the value.

    Let me know in case you need assistance on implementing this.


    Greetings,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Gilbert van Veen
    Gilbert van Veen avatar
    68 posts
    Member since:
    Oct 2009

    Posted 17 Nov 2011 Link to this post

    Thanks for the quick response, Do you have a little example?
  5. Gilbert van Veen
    Gilbert van Veen avatar
    68 posts
    Member since:
    Oct 2009

    Posted 17 Nov 2011 Link to this post

    I think it should be something like this:

    The converter:
    #region Hour value IsEnabled
      public class HourValueEnabled : System.Windows.Data.IValueConverter
      {
          ResourceManager rm = new ResourceManager("GaSuite.GaResources", typeof(Con_EditWindow).Assembly);    //Resources for translation
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              bool IsEnabled = false;
              switch (value.ToString())
              {
                  case "0":
                      //All states should match
                      IsEnabled = false;
                      break;
                  case "1":
                      //All states should match
                      IsEnabled = true;
                      break;
                  case "2":
                      //All states should match
                      IsEnabled = true;
                      break;
                  case "3":
                      //All states should match
                      IsEnabled = false;
                      break;
                  case "4":
                      //All states should match
                      IsEnabled = false;
                      break;
                  default:
                      IsEnabled = false;
                      break;
              }
              return IsEnabled;
          }
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              return value;
          }
      }
      #endregion Hour value IsEnabled

    The XAML:
    <telerik:GridViewDataColumn Header="Value" Width="100" DataMemberBinding="{Binding HourValue, Mode=TwoWay}">
                                   <telerik:GridViewColumn.CellTemplate>
                                       <DataTemplate>
                                           <telerik:RadNumericUpDown ValueFormat="Numeric" CustomUnit="%" NumberDecimalDigits="2" Value="{Binding Value, Mode=TwoWay}" Minimum="1" Maximum="100" SmallChange="1" IsEnabled="{Binding HourType, Converter={StaticResource HourValueFormatter}}" />
                                       </DataTemplate>
                                   </telerik:GridViewColumn.CellTemplate>
                               </telerik:GridViewDataColumn>
                                 
                               <telerik:GridViewDataColumn Header="Type" Width="150">
                                   <telerik:GridViewColumn.CellTemplate>
                                       <DataTemplate>
                                           <telerik:RadComboBox Name="TypeComboBox" DisplayMemberPath="TypeDescription" SelectedValuePath="TypeId" SelectedValue="{Binding HourType, Mode=TwoWay}" ItemsSource="{Binding CategoryTypes, Source={StaticResource CategoryTypeList}}" />
                                       </DataTemplate>
                                   </telerik:GridViewColumn.CellTemplate>
                               </telerik:GridViewDataColumn>

    Pave, many thanks for pointing me into the wright direction!
Back to Top