Selecting a cell in DataGrid to execute a function

2 posts, 0 answers
  1. Evan
    Evan avatar
    13 posts
    Member since:
    Sep 2017

    Posted 29 Nov 2017 Link to this post

    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

     

     

     

     

     

  2. Yana
    Admin
    Yana avatar
    5013 posts

    Posted 01 Dec 2017 Link to this post

    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
Back to Top