OnClickListener for specific row

I would like to set OnclickListener for DataGrid and copy row data(when row is clicked) to string variable. How can i do it?

3 Replies

SS Sivaraman Sivagurunathan Syncfusion Team March 3, 2020 08:36 AM UTC

Hi BrBR,  

Thank you for using Syncfusion controls.   

You can get the RowData using GridTapped event instead of override the OnclickListener for the DataGrid. GridTapped triggered when the row is tap. We have prepared the sample for your requirement. In this sample we have get the row data from GridTapped event and display the data using AlertDialog. You can download the sample from the below link. 
 


protected override void OnCreate(Bundle savedInstanceState) 
{ 
    base.OnCreate(savedInstanceState); 
    dataGrid = new SfDataGrid(this); 
    viewModel = new ViewModel(); 
    dataGrid.ItemsSource = viewModel.OrdersInfo; 
    dataGrid.GridTapped += DataGrid_GridTapped; 
    SetContentView(dataGrid); 
} 
 
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    var rowData = (e.RowData as OrderInfo).OrderID.ToString(); 
    Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    AlertDialog alert = dialog.Create(); 
    alert.SetTitle("Title"); 
    alert.SetMessage(rowData); 
    alert.Show(); 
} 


Please refer the below UG link. 



Regards,  
Sivaraman S 
 



SS Sivaraman Sivagurunathan Syncfusion Team March 3, 2020 08:37 AM UTC

Hi BrBR,  

Thank you for using Syncfusion controls.   

You can get the RowData using GridTapped event instead of override the OnclickListener for the DataGrid. GridTapped triggered when the row is tap. We have prepared the sample for your requirement. In this sample we have get the row data from GridTapped event and display the data using AlertDialog. You can download the sample from the below link. 
 


protected override void OnCreate(Bundle savedInstanceState) 
{ 
    base.OnCreate(savedInstanceState); 
    dataGrid = new SfDataGrid(this); 
    viewModel = new ViewModel(); 
    dataGrid.ItemsSource = viewModel.OrdersInfo; 
    dataGrid.GridTapped += DataGrid_GridTapped; 
    SetContentView(dataGrid); 
} 
 
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    var rowData = (e.RowData as OrderInfo).OrderID.ToString(); 
    Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    AlertDialog alert = dialog.Create(); 
    alert.SetTitle("Title"); 
    alert.SetMessage(rowData); 
    alert.Show(); 
} 


Please refer the below UG link. 



Regards,  
Sivaraman S 
 



SS Sivaraman Sivagurunathan Syncfusion Team March 3, 2020 09:09 AM UTC

Hi BrBR,  

Thank you for using Syncfusion controls.   

You can get the RowData using GridTapped event instead of override the OnclickListener for the DataGrid. GridTapped triggered when the row is tap. We have prepared the sample for your requirement. In this sample we have get the row data from GridTapped event and display the data using AlertDialog. You can download the sample from the below link. 
 


protected override void OnCreate(Bundle savedInstanceState) 
{ 
    base.OnCreate(savedInstanceState); 
    dataGrid = new SfDataGrid(this); 
    viewModel = new ViewModel(); 
    dataGrid.ItemsSource = viewModel.OrdersInfo; 
    dataGrid.GridTapped += DataGrid_GridTapped; 
    SetContentView(dataGrid); 
} 
 
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    var rowData = (e.RowData as OrderInfo).OrderID.ToString(); 
    Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    AlertDialog alert = dialog.Create(); 
    alert.SetTitle("Title"); 
    alert.SetMessage(rowData); 
    alert.Show(); 
} 


Please refer the below UG link. 



Regards,  
Sivaraman S 
 


Loader.
Up arrow icon