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

RadNumUpdown IsEnabled binding

3 Answers 21 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gilbert van Veen
Top achievements
Rank 1
Gilbert van Veen asked on 17 Nov 2011, 03:18 PM
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>

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 17 Nov 2011, 03:23 PM
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 >>

0
Gilbert van Veen
Top achievements
Rank 1
answered on 17 Nov 2011, 03:27 PM
Thanks for the quick response, Do you have a little example?
0
Gilbert van Veen
Top achievements
Rank 1
answered on 17 Nov 2011, 03:40 PM
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!
Tags
GridView
Asked by
Gilbert van Veen
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Gilbert van Veen
Top achievements
Rank 1
Share this question
or