getting row as gridviewrow don't work?

8 posts, 0 answers
  1. Kristof Van Cauwenberghe
    Kristof Van Cauwenberghe avatar
    9 posts
    Member since:
    Apr 2010

    Posted 17 Jan 2011 Link to this post

    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
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 17 Jan 2011 Link to this post

    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>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristof Van Cauwenberghe
    Kristof Van Cauwenberghe avatar
    9 posts
    Member since:
    Apr 2010

    Posted 18 Jan 2011 Link to this post

    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

  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 18 Jan 2011 Link to this post

    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>>
  6. Richa
    Richa avatar
    4 posts
    Member since:
    May 2011

    Posted 02 Feb 2012 Link to this post

    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)
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 02 Feb 2012 Link to this post

    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 >>

  8. Richa
    Richa avatar
    4 posts
    Member since:
    May 2011

    Posted 03 Feb 2012 Link to this post

    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.
  9. Sajid Ali
    Sajid Ali avatar
    12 posts
    Member since:
    Aug 2010

    Posted 08 Mar 2013 Link to this post

      <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..
Back to Top
UI for WPF is Visual Studio 2017 Ready