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

Finding the GridViewRow from a RadGridView object

9 Answers 816 Views
GridView
This is a migrated thread and some comments may be shown as answers.
GEB
Top achievements
Rank 1
GEB asked on 02 Mar 2009, 07:46 PM
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?

9 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 03 Mar 2009, 12:47 PM
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.
0
GEB
Top achievements
Rank 1
answered on 03 Mar 2009, 07:41 PM
Works great! Thanks.
0
Hector
Top achievements
Rank 1
answered on 24 Jun 2009, 03:41 PM
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.
0
Pavel Pavlov
Telerik team
answered on 25 Jun 2009, 02:51 PM

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.
0
Hector
Top achievements
Rank 1
answered on 25 Jun 2009, 03:09 PM
Hi pavel.  I have described what I want to achieve in this post with the code that I am using. 

Thank you!
0
Anwar Arakkal
Top achievements
Rank 1
answered on 10 Jul 2009, 07:31 AM
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
0
Vlad
Telerik team
answered on 10 Jul 2009, 11:32 AM
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.
0
Anwar Arakkal
Top achievements
Rank 1
answered on 11 Jul 2009, 09:18 AM
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
0
Milan
Telerik team
answered on 13 Jul 2009, 05:05 AM
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.
Tags
GridView
Asked by
GEB
Top achievements
Rank 1
Answers by
Jordan
Telerik team
GEB
Top achievements
Rank 1
Hector
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Anwar Arakkal
Top achievements
Rank 1
Vlad
Telerik team
Milan
Telerik team
Share this question
or