Finding the GridViewRow from a RadGridView object

10 posts, 0 answers
  1. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 02 Mar 2009 Link to this post

    I am able to get to the GridViewRow object during a drop operation into a RadGridView.  I am also able to get to the GridViewRow when handling the RowLoaded event.  However, I'm strugglig getting to a GridViewRow object from a RadGridView object.

    What I'm trying to do is determine the selected row(s) (i.e., RadGridView.SelectedRecords), then find the GridViewRow for each selected record so that I can change the colors of the cells.  However, starting with a RadGridView object, I cannot find a way to get to the GridViewRow objects associated with the RadGridView.  How do I do this?

  2. Jordan
    Admin
    Jordan avatar
    123 posts
    Member since:
    Sep 2012

    Posted 03 Mar 2009 Link to this post

    Hi Geb,


    Unfortunately, our API does not provide an easy way to get a GridViewRow from the RadGridView.
    You have to use the ItemsGenerator property of the GridViewItemsControl to get the GridViewRow for a given index. You can get that index from the DataRecord corresponding to the data item.

    See the code bellow:
    DataRecord record = (DataRecord)this.gridView.FindRecord(/* data object */); 
    bool isNewlyCreated = false
    ridViewRow item = (GridViewRow)this.gridView.ItemsControl.ItemsGenerator.GenerateItemAtIndex(record.DataSourceIndex, out isNewlyCreated); 
    item.IsSelected = true


    Sincerely yours,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  3. Download a free trial of UI for WPF
  4. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 03 Mar 2009 Link to this post

    Works great! Thanks.

  5. Hector
    Hector avatar
    91 posts
    Member since:
    May 2009

    Posted 24 Jun 2009 Link to this post

    This code will not work for grouped rows.  How can I make this same code work if my GridView is grouped?  The GenerateItemAtIndex returns a GridViewGroupRow, not a GridViewRow. 

    GridViewRow item = (GridViewRow)this.gridView.ItemsControl.ItemsGenerator.GenerateItemAtIndex(record.DataSourceIndex, out isNewlyCreated);

    Thanks.

  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2022 posts
    Member since:
    Sep 2012

    Posted 25 Jun 2009 Link to this post

    Hi Hector,

    Can you please give me more details on  your specific scenario. Meanwhile the RadGridView API  has evolved and I believe we can find a better solution here.

    Do you need access to the selected rows , or you need the row over which the user clicked or you need the UI row for a given datasource element  ..or something else ?

    If I have more details I will gladly provide you with a working sample.

    Best wishes,

    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  7. Hector
    Hector avatar
    91 posts
    Member since:
    May 2009

    Posted 25 Jun 2009 Link to this post

    Hi pavel.  I have described what I want to achieve in this post with the code that I am using. 

    Thank you!

  8. Anwar Arakkal
    Anwar Arakkal avatar
    21 posts
    Member since:
    Nov 2007

    Posted 10 Jul 2009 Link to this post

    Hi,

    I am having anotyher issue.
    I have create a grid column as shown below

    <grid:GridViewColumn HeaderText="Trend" Width="120">
                            <grid:GridViewColumn.CellStyle>
                                <Style TargetType="gridView:GridViewCell">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="gridView:GridViewCell">
                                                <Border BorderThickness="0,0,0,1" BorderBrush="#FFB3B3B3">
                                                    <StackPanel Orientation="Horizontal">
                                                        <Button x:Name="btnTrend" Content="Trend" ></Button>
                                                    </StackPanel>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </grid:GridViewColumn.CellStyle>
                        </grid:GridViewColumn>

    I need to enable or disable the the button(btnTrend) on the RowLoaded event. I am not able to find the control in RowLoaded event.
    Can you please help me on resolving this request? Please correct me if the above XAML code is wrong.

    Thanks,
    Anwar

  9. Vlad
    Admin
    Vlad avatar
    11043 posts
    Member since:
    Sep 2012

    Posted 10 Jul 2009 Link to this post

    Hi Anwar,

    You can use our extension methods to find this button:

    var button = e.Row.ChildrenOfType<Button>().Where(b=>b.Name == "btnTrend").FirstOrDefault();
    if(button != null)
    {
       // your code goes here
    }

    Best wishes,
    Vlad
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  10. Anwar Arakkal
    Anwar Arakkal avatar
    21 posts
    Member since:
    Nov 2007

    Posted 11 Jul 2009 Link to this post

    Hi,

    Thanks for the quick response.But it did not work for me. I am not able to get the function called "ChildrenOfType". I have installed the latest DLL's. Still no luck?
    Here is the error message
    Error 1 'Telerik.Windows.Controls.GridView.GridViewRowItem' does not contain a definition for 'ChildrenOfType' and no extension method 'ChildrenOfType' accepting a first argument of type 'Telerik.Windows.Controls.GridView.GridViewRowItem' could be found (are you missing a using directive or an assembly reference?) E:\Projects\AFAttributeViewerSL\AFAttributeViewerSL\Page.xaml.cs 81 32 AFAttributeViewerSL

    Can you please solve this issue?

    Thanks,
    Anwar

  11. Milan
    Admin
    Milan avatar
    1989 posts
    Member since:
    Jul 2013

    Posted 13 Jul 2009 Link to this post

    Hello Anwar Arakkal,

    To be able to access the ChildrenOfType method you will have to unclude the Telerik.Windows.Controls namespace.

    using Telerik.Windows.Controls; 

    That should fix the problem.

    Regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

Back to Top
Download a free trial of UI for WPF