Problem binding TabStopMode on GridViewDataColumn

4 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Mar 2013

    Posted 03 May 2013 Link to this post

    I'm attempting to set the TabStopMode in some way via binding. After attempting several ways of doing this that didn't work I'm now attempting to use a converter.

    My GridViewDataColumn definition looks like this.
    <telerik:GridViewDataColumn x:Name="RequestedQty" 
         DataMemberBinding="{Binding RequestedQty, StringFormat='n'}" 
         Header="Req Qty" Width="75" TextAlignment="Right" 
         HeaderTextAlignment="Right"  
         TabStopMode="{Binding StepIsReadOnly, 
              Converter={StaticResource BooleanToTabStopModeConverter}}"/>

    StepIsReadOnly is a property in the object the row is bound to so it's at the same level as RequestedQty.

    The problem is that when i run this i get the following in the Immediate Window.

    System.Windows.Data Error: 40 : BindingExpression path error: 'StepIsReadOnly' property not found on 'object' ''BatchFixDataEntryViewModel' (HashCode=24249959)'. BindingExpression:Path=StepIsReadOnly; DataItem='BatchFixDataEntryViewModel' (HashCode=24249959); target element is 'GridViewDataColumn' (HashCode=19523191); target property is 'TabStopMode' (type 'GridViewTabStop')


    It looks like the binding for TabStopMode is looking at the overall data context (view model) for the window instead of at the data context for the row.

    Thanks,
    Dave
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 May 2013 Link to this post

    Hello,

    You are right, the TabStopMode should be bound to a property defined in the ViewModel. Please define the StepIsReadOnly property for your model.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. David
    David avatar
    4 posts
    Member since:
    Mar 2013

    Posted 08 May 2013 Link to this post

    Didie,

    Since some rows are readonly and others aren't having the property at the ViewModel level is rather useless!

    Why would one expect this to work this way? All other bindings that I'm aware of are to the context for the row. To me this seems like a bug that should be fixed.

    Given that this works this way now, how can I access the property of the row item instead of one at the ViewModel level? I'm new enough at WPF so that this isn't second nature to me yet. I'm guessing it's something like this.
    TabStopMode="{Binding Item.StepIsReadOnly, 
              RelativeSource={RelativeSource Self}, 
              Converter={StaticResource BooleanToTabStopModeConverter}}"

    This doesn't work as what gets referneced is the GridViewDataColumn not the specific cell.

    Suggestions?

    Thanks,
    Dave
  4. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 10 May 2013 Link to this post

    Hello,

    Indeed you cannot set binding that way. You may use RadGridView.CurrentCellInfo.Item to reference the current item.

    <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                                Header="Est." TabStopMode="{Binding CurrentCellInfo.Item.Name, ElementName=clubsGrid, Converter={StaticResource testConverter}}"
                                                DataFormatString="{}{0:yyyy}"/>

    Unfortunately when GridViewDataColumn is created CurrentCellInfo object is null and binding will not work again. However you could recalculate it within CurrentCellChanged event handler:

    private void clubsGrid_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
            {
                foreach (var col in this.clubsGrid.Columns)
                {
                    BindingExpression be = col.ReadLocalValue(Telerik.Windows.Controls.GridViewColumn.TabStopModeProperty) as BindingExpression;
                    if (be != null)
                    {
                        be.UpdateTarget();
                    }
                }
            }

    Greetings,
    Nedyalko Nikolov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top