0

I'm using telerik:RadgridView control in my MVVM WPF application. In a scenario i have to compare tow properties and set a property IsReadOnlybinding to "True" or "False" for the column.

//Code:

    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnlyBinding="{Binding IsExists }" >    
        <telerik:GridViewDataColumn.CellEditTemplate>
                     <DataTemplate>
                           <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="30" SelectionLength="30" />
                     </DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
    </telerik:GridViewDataColumn>

In the above code i have checked IsExists property and made the column ReadOnly. Now i have to check another property "Id". If the Id property is greater than 0 and IfExists is True then make the column ReadOnly.

How can i achieve this?

A Coder
  • 3,039
  • 7
  • 58
  • 129

1 Answers1

1

I hereby given an answer in which I've used TextBox instead of RadGridView and used IsReadOnly property instead of IsReadOnlyBinding (as I dont have telerik controls access).

Below is Xaml:

<TextBox Text="{Binding TextProp}" Height="30" Width="100" >
        <TextBox.IsReadOnly>
            <MultiBinding Converter="{StaticResource existingToBoolConverter}">
                <Binding Path="IsExisting"/>
                <Binding Path="ID"/>
            </MultiBinding>
        </TextBox.IsReadOnly>
    </TextBox>

And my ViewModel

public class ViewModel
{
    public string TextProp { get; set; }
    public bool IsExisting { get; set; }
    public int ID { get; set; }
    public ViewModel()
    {
        TextProp = "Some Text";
        IsExisting = true;
        ID = 1;
    }
}

And the converter as follows:

public class IsExistToBooleanConverter : IMultiValueConverter
{

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (((bool)values[0]) && ((int)values[1]) != 0)
            return false;
        else
           return true;

    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Hope this helps you.

Thanks, Karuppasamy

Karuppasamy
  • 206
  • 1
  • 7
  • Thanks for your reply, but i need to do for a Telerik:RadGridView. Since the RadGridView doesnt have readonly property to each cell i'm looking for an alternative. – A Coder Jul 16 '15 at 05:02
  • IsReadOnlyBinding is a bool property of GridViewDataColumn, to which you are going to bind the Model's property right? That might be works. But I am sorry for misunderstanding, if I am wrong. I would have check this one if I have telerik access, even I will try to check. Better you try to do a simple sample app with this. Have a good day :) – Karuppasamy Jul 16 '15 at 05:14
  • Yes its a boolean property which is set to the column. I need to bind the property to the column and not to the control since i have CheckBoxcolumn, ComboBoxColumn.. etc.. Thanks – A Coder Jul 16 '15 at 05:18
  • yeah, why do you think, you can't set this to Column( GridViewDataColumn or GridViewCheckBoxColumn or whatever)? Are you using AutogeneratingColumns to true ? – Karuppasamy Jul 16 '15 at 05:21
  • Hope should work, i'll check and let you know. Thanks for your help & time. – A Coder Jul 16 '15 at 05:33
  • isn't supporting multi binding. Throwing "cannot set multibinding because multivalueconverter must be specified" error. Added converter and reference also. – A Coder Jul 16 '15 at 06:13
  • There are some questions with the same error in SOF, please refer, http://stackoverflow.com/questions/19510196/multibinding-generates-cannot-set-multibinding-because-multivalueconverter-must and http://stackoverflow.com/questions/25247992/multibinding-with-binding-stringformat – Karuppasamy Jul 16 '15 at 07:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83395/discussion-between-karuppasamy-and-santhosh-kumar). – Karuppasamy Jul 16 '15 at 07:02