Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > GridView > Finding the GridViewRow from a RadGridView object

Not answered Finding the GridViewRow from a RadGridView object

Feed from this thread
  • GEB Master avatar

    Posted on Mar 2, 2009 (permalink)

    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?

    Reply

  • Jordan Jordan admin's avatar

    Posted on Mar 3, 2009 (permalink)

    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.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • GEB Master avatar

    Posted on Mar 3, 2009 (permalink)

    Works great! Thanks.

    Reply

  • Hector Intermediate avatar

    Posted on Jun 24, 2009 (permalink)

    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.

    Reply

  • Pavel Pavlov Pavel Pavlov admin's avatar

    Posted on Jun 25, 2009 (permalink)

    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.

    Reply

  • Hector Intermediate avatar

    Posted on Jun 25, 2009 (permalink)

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

    Thank you!

    Reply

  • Anwar Arakkal avatar

    Posted on Jul 10, 2009 (permalink)

    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

    Reply

  • Vlad Vlad admin's avatar

    Posted on Jul 10, 2009 (permalink)

    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.

    Reply

  • Anwar Arakkal avatar

    Posted on Jul 11, 2009 (permalink)

    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

    Reply

  • Milan Milan admin's avatar

    Posted on Jul 13, 2009 (permalink)

    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.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > GridView > Finding the GridViewRow from a RadGridView object
Related resources for "Finding the GridViewRow from a RadGridView object"

Silverlight Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]