I am trying to show the detailvisibility from a row after filling up the gridview.
but the row i receive row=... is always nothing.
I found the code to retrieve the row in an other forumthread.
but it is not working.
I work with the latest version of the controls.
Dim dt As datatable
dt = getdatatable.defaultview
Me.radDataPager.Source = dt
radDataPager.MoveToLastPage()
Dim row As Telerik.Windows.Controls.GridView.GridViewRow
row = Me.radGridView.ItemContainerGenerator.ContainerFromIndex(radGridView.Items.Count - 1)
row.DetailsVisibility = Visibility.Visible
Thanks
Kristof
7 Answers, 1 is accepted
Generally it will return null if the item is outside of the viewable area. Can you please try the following code snippet and let me know how this works for you:
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
DataContext
=
"{Binding Source={StaticResource SampleDataSource}}"
>
<
Grid.Resources
>
<
DataTemplate
x:Key
=
"dt"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"Windows Presentation Foundation"
Margin
=
"5"
Width
=
"100"
Height
=
"100"
/>
<
TextBlock
Text
=
"Silverlight"
Margin
=
"5"
Width
=
"100"
Height
=
"100"
/>
</
StackPanel
>
</
DataTemplate
>
</
Grid.Resources
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
telerik:RadGridView
RowDetailsTemplate
=
"{StaticResource dt}" IsSyncrhonizedWithCurrentItem="True"
x:Name
=
"radGridView1"
ItemsSource
=
"{Binding Collection}"
/>
<
telerik:RadButton
x:Name
=
"radButton1"
Grid.Row
=
"1"
Content
=
"Hide First Column"
Click
=
"radButton1_Click"
/>
</
Grid
>
Private
Sub
radButton1_Click(sender
As
Object
, e
As
System.Windows.RoutedEventArgs)
' TODO: Add event handler implementation here.
Dim
row = TryCast(
Me
.radGridView1.ItemContainerGenerator.ContainerFromItem(
Me
.radGridView1.SelectedItem), GridViewRow)
If
row IsNot
Nothing
Then
row.DetailsVisibility = Visibility.Visible
End
If
End
Sub
Please let me know if you need any further assistance.
Regards,
Vanya Pavlova
the Telerik team
Can you help me? (I am new with binding in WPF)
if i use your code he don't know:
IsSyncrhonizedWithCurrentItem
="True"
if i remove this he don't know:
StaticResource
SampleDataSource
so i think i need to add more code, but i already looked at the examples but can't find it.
Kind regards
Kristof
Let me try to explain how the example below works:
When you set IsSynchronizedWithCurrentItem to true the first row in RadGridView is automatically selected. Remove this property from RadGridView's definition select an item in RadGridView and click the button to get the corresponding RowDetails.
You may extend the example in the way you need.
Vanya Pavlova
the Telerik team
Let me know how can I get row having all cells (including cell visible and not visible because of scroll bar)
You should never rely on visual elements because with virtualization turned on, not all of them are realized.
Instead, you should always work with data items. The DataContext of each GridViewRow is the respective underlying data item (business object, POCO or whatever it may be called). So, you should read your information from the data item and not from the physical cells.
I hope this helps.
Ross
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I am facing one more issue. If I select a gridview, whole gridview is selected having red color border line. It will be great help if you can tell me to reomve this red line.
<telerik:RadGridView x:Name="grdRoles" ItemsSource="{Binding RoleResources}" SelectedItem="{Binding SelectedRoleResource, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" customCommands:RadGridViewRowEditEnded.Command="{Binding Path=cmdRowEditEnded}" ShowGroupPanel="False" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserDeleteRows="False" ShowInsertRow="False" IsFilteringAllowed="False" IsSynchronizedWithCurrentItem="True" RowIndicatorVisibility="Collapsed"> <telerik:RadGridView.Columns> <telerik:GridViewColumn Header=" " Width="30"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Path=IsSelected,Mode=TwoWay}"/> </DataTemplate> </telerik:GridViewColumn.CellTemplate> </telerik:GridViewColumn> <telerik:GridViewColumn Header="Name" Width="100*"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <telerik:Label Content="{Binding Path=Name}"/> </DataTemplate> </telerik:GridViewColumn.CellTemplate> <telerik:GridViewColumn.CellEditTemplate> <DataTemplate> <TextBox Text="{Binding Path=Name,Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"/> </DataTemplate> </telerik:GridViewColumn.CellEditTemplate> </telerik:GridViewColumn>
</telerik:RadGridView.Columns> </telerik:RadGridView> Here is my code that add the new row in the view model as I am using the MVVM pattern.Can anybody explain me what i am doing wrong..private void NewRoleResource(String arg) { // Check if an empty row is already added RoleResourceViewModel emptyRoleResource = RoleResources.FirstOrDefault(c => string.IsNullOrEmpty(c.Name)); if (emptyRoleResource == null) { RoleResource model = new RoleResource(); emptyRoleResource = new RoleResourceViewModel(model, _eventAggregator); RoleResources.Add(emptyRoleResource); SelectedRoleResource = emptyRoleResource;This is my view contstructorSelectedRoleResource.Name = "Name";// temporarily hold the object newTempRoleResource = emptyRoleResource; if (NewRowAdded != null) { NewRowAdded(SelectedRoleResource, null); } } }public RolesView(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator) : this() { EditRolesViewModel vm = ServiceLocator.Current.GetInstance<EditRolesViewModel>(); this.DataContext = vm; vm.NewRowAdded += new EventHandler(OnNewRowAdded); } void OnNewRowAdded(object sender, EventArgs e) { GridViewRow row = (GridViewRow)grdRoles.ItemContainerGenerator.ContainerFromItem(grdRoles.SelectedItem); // Row is always null although you can find the newly inserted item in the grdRoles.SelectedItem if (row != null) { row.IsCurrent = true; row.Cells[1].Focus(); grdRoles.BeginEdit(); } }