Articles in this section
Category / Section

How do you open a image file from DataGridTemplateColumn in .NET MAUI DataGrid (SfDataGrid) ?

3 mins read

In this article, we will demonstrate how to open an image file from a DataGridTemplateColumn in the .NET MAUI DataGrid.

xaml

<syncfusion:SfDataGrid x:Name="sfGrid"
                       SelectionMode="Single"
                       NavigationMode="Cell"
                       GridLinesVisibility="Both"
                       ColumnWidthMode="Auto"
                       HeaderGridLinesVisibility="Both"
                       AutoGenerateColumnsMode="None"
                       ItemsSource="{Binding Employees}">

    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridTextColumn MappingName="EmployeeID"
                                       HeaderText="Employee ID" />
        <syncfusion:DataGridTextColumn MappingName="Name"
                                       HeaderText="Employee Name" />
        <syncfusion:DataGridTextColumn MappingName="Designation"
                                       HeaderText="Designation" />
        <syncfusion:DataGridTemplateColumn HeaderText="Image">
            <syncfusion:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ImageButton Source="dot_icon.png"
                                 Clicked="ImageButton_Clicked" />
                </DataTemplate>
            </syncfusion:DataGridTemplateColumn.CellTemplate>
        </syncfusion:DataGridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

C#
The code below illustrates how to open an image file from a DataGridTemplateColumn in a DataGrid.

private void ImageButton_Clicked(object sender, EventArgs e)
{
    var imageButton = sender as ImageButton;
    var rowData = (imageButton.BindingContext as Employee);

    if (rowData != null)
    {
        // Assuming you have a method to show the image
        ShowPartImage(rowData.URL);
    }
}

private async Task ShowPartImage(string imageUrl)
{
    // Implement your logic to display the image
    // For example, you can open a new page or a popup with the image
    await Navigation.PushAsync(new PartImage(imageUrl));
}

Output

OpenImg.gif

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to open an image file from a DataGridTemplateColumn in .NET MAUI DataGrid (SfDataGrid).

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

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, or the feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied