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

getting row as gridviewrow don't work?

7 Answers 195 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kristof Van Cauwenberghe
Top achievements
Rank 1
Kristof Van Cauwenberghe asked on 17 Jan 2011, 03:01 PM
Hi

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

Sort by
0
Vanya Pavlova
Telerik team
answered on 17 Jan 2011, 05:04 PM
Hi Kristof,

 
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
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kristof Van Cauwenberghe
Top achievements
Rank 1
answered on 18 Jan 2011, 09:04 AM
Hi

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

0
Vanya Pavlova
Telerik team
answered on 18 Jan 2011, 05:09 PM
Hi 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.

Regards,
Vanya Pavlova
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richa
Top achievements
Rank 1
answered on 02 Feb 2012, 01:02 PM
I am trying to get full row from gridview.selectedItem. but I am only able to get visible cells of the row.


Let me know how can I get row having all cells (including cell visible and not visible because of scroll bar)
0
Rossen Hristov
Telerik team
answered on 02 Feb 2012, 01:15 PM
Hi,

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.

Regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Richa
Top achievements
Rank 1
answered on 03 Feb 2012, 06:34 AM
Thanks for your quick reply. 

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.
0
Sajid Ali
Top achievements
Rank 2
answered on 08 Mar 2013, 11:35 AM
  <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.

 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;

 
		SelectedRoleResource.Name = "Name";
                // temporarily hold the object                 newTempRoleResource = emptyRoleResource;                 if (NewRowAdded != null)                 {                     NewRowAdded(SelectedRoleResource, null);                 }             }         }
This is my view contstructor
 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(); 
            }
        }
Can anybody explain me what i am doing wrong..
Tags
GridView
Asked by
Kristof Van Cauwenberghe
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Kristof Van Cauwenberghe
Top achievements
Rank 1
Richa
Top achievements
Rank 1
Rossen Hristov
Telerik team
Sajid Ali
Top achievements
Rank 2
Share this question
or