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

[Solved] CurrentItem

7 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jennifer
Top achievements
Rank 1
Jennifer asked on 28 Oct 2009, 11:40 PM
How do I get the current row I am on in the grid. I have a grid with a MODIFY and DELETE button in each row and I need to know which row they are on when they click the button. Or should I being doing this differently. I want to have them MODIFy in an another window instead of in the grid.

I tried using this binding but its always "0".
CurrentItem="{Binding TemplatesGridIndex, Mode=TwoWay}"

Thanks

Here is my grid XAML code

<telerikGridView:RadGridView x:Name="radGridViewTemplates"  
                         AutoGenerateColumns="False"  IsFilteringAllowed="False"  ShowGroupPanel="False"   
                        ItemsSource="{Binding MyTemplates}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                        CurrentItem="{Binding TemplatesGridIndex, Mode=TwoWay}"  >
                        <telerikGridView:RadGridView.Columns>
                            <telerikGridView:GridViewColumn>
                                
                                <telerikGridView:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="btnModify" Content="Edit" Click="btnModify_Click"  />
                                    </DataTemplate>
                                </telerikGridView:GridViewColumn.CellTemplate>
                            </telerikGridView:GridViewColumn>
                            
                            <telerikGridView:GridViewColumn>
                                <telerikGridView:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="btnDelete" Content="Delete" />
                                    </DataTemplate>
                                </telerikGridView:GridViewColumn.CellTemplate>
                            </telerikGridView:GridViewColumn>
                            <telerikGridView:GridViewColumn>
                                <telerikGridView:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Image Source="{Binding Path=ImageURL, Converter={StaticResource ImageConverter}}"  Height="50" Width="100" Stretch="UniformToFill"  />
                                    </DataTemplate>
                                </telerikGridView:GridViewColumn.CellTemplate>
                            </telerikGridView:GridViewColumn>
                            <telerikGridView:GridViewDataColumn
                                HeaderText="Title" HeaderTextAlignment="Left" DataMemberBinding="{Binding Title}" />
                            <telerikGridView:GridViewDataColumn
                                HeaderText="Description" HeaderTextAlignment="Left" DataMemberBinding="{Binding Description}"/>
                        </telerikGridView:RadGridView.Columns>
                    </telerikGridView:RadGridView>


7 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 29 Oct 2009, 10:34 AM
Hello Jennifer,

You could use our ParentOfType extension method to get the parent row when you click on a button:

// required namespace: using Telerik.Windows.Controls;
private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var senderElement = sender as FrameworkElement;
    var parentRow = senderElement.ParentOfType<GridViewRow>();
    var parentDataItem = parentRow.DataItem;
}


All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Virendra
Top achievements
Rank 1
answered on 29 Oct 2009, 10:51 AM
when i pasted above code,

For "GridViewRow" it shows Type or Namespace name is not found...
I can see "GridViewColumn" but not "GridViewRow" in variable list.

Thanks
virendra



0
Vlad
Telerik team
answered on 29 Oct 2009, 11:42 AM
Hello Virendra,

You can use the Visual Studio IntelliSence to add needed namespace - this this case Telerik.Windows.Controls.GridView.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jennifer
Top achievements
Rank 1
answered on 29 Oct 2009, 05:36 PM
Beautiful.  It worked. Thanks
0
Jennifer
Top achievements
Rank 1
answered on 09 Nov 2009, 09:39 PM
I am a little confused with knowing the current row of a grid.

I am looking at a college's code who used the datagrid that comes with Visual Studio Silverlight. He has this in his XAML:

 <data:DataGrid x:Name="dgConfigSettings" Grid.Row="2" AutoGenerateColumns="False" ItemsSource="{Binding KioskConfigSettingsDataSource}" SelectedIndex="{Binding ConfigSettingsDGIndex, Mode=TwoWay}">
                              
Then he has a DELETE button in one of his columns.  When that is clicked, the row index is contained in
"ConfigSettingsDGIndex".

Then he can just use this to remove the current row from the grid:
         KioskConfigSettingsDataSource.RemoveAt(ConfigSettingsDGIndex);
where
        KioskConfigSettingsDataSource is an Observable Collection bound to grid

How can I do this with the Telerik grid?

Thanks



0
Vlad
Telerik team
answered on 10 Nov 2009, 06:42 AM
Hello,

I've attached small example to illustrate you how to achieve your goal.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jennifer
Top achievements
Rank 1
answered on 10 Nov 2009, 04:22 PM
Now I am getting it. Thanks so much for your help. Worked perfectly.
Its been quite a learning curve for me even coming from an ASP.NET background.
And we are using the Prism libraries as well.
Tags
GridView
Asked by
Jennifer
Top achievements
Rank 1
Answers by
Milan
Telerik team
Virendra
Top achievements
Rank 1
Vlad
Telerik team
Jennifer
Top achievements
Rank 1
Share this question
or