Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add GestureRecognizer to row in gridview

I have a grid where there are 3 columns containing 2 buttons and 1 label. What I want is to add a Tap gesture to each rows in the grid. I want the click event to be fired when the user taps anywhere in the grid row. Is there any way to do this?

I want to keep my layout as simple as possible. Before I was creating the same grid using multiple stacklayouts and adding gestures to the parent stacklayout. But for performance I want to do this using a grid view.

like image 346
Akash Amin Avatar asked May 24 '16 13:05

Akash Amin


People also ask

How to generate rows in a GridView from DataTable?

As you can see, we define four Columns in the DataTable called RowNumber, Column1, Column2 and Column3. The RowNumber column will serve as the key for generating the rows in the GridView. Noticed that for Columns 1, 2 and 3, I assigned an empty value for those columns since the GridView will be generated for the first time.

How to generate rows of textbox in GridView using Visual Studio toolbox?

To get started, let’s grab a GridView control from the Visual Studio Toolbox and put it in the Web Form. The mark up would look something like this: Since this demo is intended to generate rows of TextBox in GridView, then we set up some Template Fields columns so that GridView will automatically generates TextBoxes when a new row is being added.

How do I display row details in a DataGrid?

In the DataGrid element, add a RowDetailsTemplate element. Create a DataTemplate that defines the appearance of the row details section. The following XAML shows the DataGrid and how to define the RowDetailsTemplate inline. The DataGrid displays three values in each row and three more values when the row is selected.

How do I assign a value to a cell in GridView?

It is necessary to use the GridView.SetRowCellValue method if you wish to assign a value to a cell as described in the Obtaining and Setting Cell Values help article. However, if you deal with an unbound column, such a column does not have any data storage.


1 Answers

I would suggest adding a ContentView (which is not as intensive as a StackLayout). Make it cover the whole row and add the GestureRecognizer to that, like so:

<ContentView HorizontalOptions="FillAndExpand"
             VerticalOptions="FillAndExpand"
             Grid.Row="0"
             Grid.Column="0"
             Grid.ColumnSpan="3">
    <ContentView.GestureRecognizers>
        <TapGestureRecognizer Tapped="OnTapped"/>
    </ContentView.GestureRecognizers>
</ContentView>
like image 145
hvaughan3 Avatar answered Nov 14 '22 00:11

hvaughan3