Hello,
Although your approach for populating your
TextBoxes is a possible one, I would like to caution you that it can lead to some issues. Since
RadGridView by default uses
UI virtualization. For example if you select a row and then scroll down / up and the selected row goes out of the visible area, then your approach will not work. That is so because the
ItemContainerGenerator relies on the selected row to be in the viewport. That is why you can not rely on the visual elements when the UI Virtualization is enabled. Please note that all the visual elements (for example GridViewCell, GridViewRow) will be created as they are brought into view. Then all the visual elements will be re-created when they go beyond the visible area and then come back into view.
Another possible approach to this issue is to bind your
TextBoxes in XAML like so:
<
Grid
DataContext
=
"{StaticResource MyViewModel}"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
telerik:RadGridView
Grid.Row
=
"0"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Clubs}"
AutoGenerateColumns
=
"False"
Margin
=
"5"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Established}"
Header
=
"Est."
DataFormatString
=
"{}{0:yyyy}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding StadiumCapacity}"
Header
=
"Stadium"
DataFormatString
=
"{}{0:N0}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
<
StackPanel
Orientation
=
"Horizontal"
Grid.Row
=
"1"
>
<
TextBlock
Text
=
"Selected Row Data: "
/>
<
TextBox
Text
=
"{Binding SelectedItem.Name, ElementName=clubsGrid}"
Width
=
"200"
/>
<
TextBox
Text
=
"{Binding SelectedItem.Established, ElementName=clubsGrid}"
Width
=
"200"
/>
<
TextBox
Text
=
"{Binding SelectedItem.StadiumCapacity, ElementName=clubsGrid}"
Width
=
"200"
/>
</
StackPanel
>
</
Grid
>
I attached a sample project that demonstrates the suggested approach.
I hope this helps.
Regards,
Boris
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.