This is a migrated thread and some comments may be shown as answers.
Selecting a cell in DataGrid to execute a function
1 Answer 71 Views
This is a migrated thread and some comments may be shown as answers.
Evan
Top achievements
Rank 1
Evan asked on 29 Nov 2017, 10:51 PM

Hello
I am trying to get my DataGrid to use a method whenever a cell in the grid is selected. I have tried to use the GestureRecognizers to get the functionality but my method. Am i approaching this the wrong way? Or is there something that I am missing?

This is what I have right now for the xaml DataGrid:

<ScrollView Grid.Row="2" IsClippedToBounds="True">
                    <telerikGrid:RadDataGrid AutoGenerateColumns="False" x:Name="AssignedRolesList" Margin="10,5,0,10" SelectionMode="Single" SelectionUnit="Cell">
                        <telerikGrid:RadDataGrid.GestureRecognizers>
                            <TapGestureRecognizer Tapped="GoToOperationalPeriods"/>
                        </telerikGrid:RadDataGrid.GestureRecognizers>
                        <telerikGrid:RadDataGrid.GroupDescriptors>
                            <common:PropertyGroupDescriptor PropertyName="RoleName" />
                        </telerikGrid:RadDataGrid.GroupDescriptors>
                        <telerikGrid:RadDataGrid.Columns>
                            <telerikGrid:DataGridTextColumn PropertyName="OperationalPeriodName" HeaderText="Assigned Roles" HeaderStyle="{StaticResource DataGridHeader}" />
                        </telerikGrid:RadDataGrid.Columns>
                    </telerikGrid:RadDataGrid>
                </ScrollView>

 

 

This is what my function is on the backend:

private void GoToOperationalPeriods(object sender, EventArgs e)
        {
            RoleOperationalPeriodsDto selectedCell = (RoleOperationalPeriodsDto)AssignedRolesList.SelectedItem;
            Navigation.PushAsync(new ViewOperationalPeriods(selectedCell.OperationalPeriodId), true);
        }

 

 

Thanks,

Evan

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 01 Dec 2017, 08:09 AM
Hello Evan,

I would suggest you use the DataGrid SelectionChanged event which is fired when a cell/row is clicked/tapped.  Which element (cell or row) is considered during selection depends on the SelectionUnit property.   Here is a simple snippet:

<telerikGrid:RadDataGrid x:Name="grid" AutoGenerateColumns="False" x:Name="AssignedRolesList" Margin="10,5,0,10"
        SelectionMode="Single"
        SelectionUnit="Cell"
        SelectionChanged="grid_SelectionChanged">         
 ...
 </telerikGrid:RadDataGrid>

and the event handler:

private void grid_SelectionChanged(object sender, DataGridSelectionChangedEventArgs e)
{
 ...
}

I hope this would be helpful.

Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Evan
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or