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

Problem binding TabStopMode on GridViewDataColumn

3 Answers 95 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 May 2013, 03:13 PM
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

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 08 May 2013, 12:14 PM
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.

0
David
Top achievements
Rank 1
answered on 08 May 2013, 01:39 PM
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
0
Nedyalko Nikolov
Telerik team
answered on 10 May 2013, 01:30 PM
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.

Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
David
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or