How to Show Popup on Selecting the Same Record in .NET MAUI DataGrid?
This article demonstrates how to display a pop-up when a user selects the same record again in the .NET MAUI DataGrid. Using the SfPopup control, we can present detailed information about the selected employee in a pop-up window.
Xaml
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<Grid>
<syncfusion:SfDataGrid x:Name="sfGrid"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
ColumnWidthMode="Auto"
SelectionMode="Single"
NavigationMode="Cell"
AutoGenerateColumnsMode="None"
CellTapped="sfGrid_CellTapped"
ItemsSource="{Binding Employees}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
<!-- Syncfusion SfPopup -->
<sfPopup:SfPopup x:Name="popup"
WidthRequest="400"
HeightRequest="250"
ShowFooter="True"
ShowHeader="True"
StaysOpen="False"
IsOpen="{Binding IsPopupOpen, Mode=TwoWay}"
>
<sfPopup:SfPopup.HeaderTemplate>
<DataTemplate>
<Label Text="Employee Details" HorizontalOptions="Center"
FontSize="18"
FontAttributes="Bold" />
</DataTemplate>
</sfPopup:SfPopup.HeaderTemplate>
<sfPopup:SfPopup.ContentTemplate>
<DataTemplate>
<VerticalStackLayout Padding="10">
<Label
Text="{Binding SelectedEmployeeDetails}"
FontSize="16"
TextColor="Black" />
</VerticalStackLayout>
</DataTemplate>
</sfPopup:SfPopup.ContentTemplate>
<sfPopup:SfPopup.FooterTemplate>
<DataTemplate>
<Button Text="Close" WidthRequest="100" HeightRequest="40"
Clicked="ClosePopup" />
</DataTemplate>
</sfPopup:SfPopup.FooterTemplate>
</sfPopup:SfPopup>
</Grid>
Xaml.cs
The code below demonstrates how to show the popup when selecting the same record again in SfDataGrid.
private void ClosePopup(object sender, EventArgs e)
{
popup.IsOpen = false;
}
private void sfGrid_CellTapped(object sender, Syncfusion.Maui.DataGrid.DataGridCellTappedEventArgs e)
{
var employee = e.RowData as Employee;
if (employee != null && sfGrid.SelectedRows.Contains(employee))
{
viewModel.UpdateSelectedEmployee(employee);
}
}
// EmployeeViewModel.cs
public void UpdateSelectedEmployee(Employee employee)
{
if (employee != null)
{
SelectedEmployeeDetails = $"ID: {employee.EmployeeID}\nName: {employee.Name}\nPosition: {employee.Title}";
IsPopupOpen = true;
}
}
Output
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to show a popup on selecting the same record in .NET MAUI DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to know about its other groundbreaking feature representations and Documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI DataGrid example to understand how to create and manipulate data.
For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!