Articles in this section

How to display checkboxes with 0 and 1 values mapped from SQLite in a .NET MAUI DataGrid?

In this article, we will demonstrate how to display checkboxes with 0 and 1 values mapped from SQLite in a .NET MAUI DataGrid.

xaml:

<StackLayout>
    <syncfusion:SfDataGrid x:Name="dataGrid"
                            SelectionMode="Single"
                            AutoGeneratingColumn="dataGrid_AutoGeneratingColumn"
                            NavigationMode="Cell">

        <syncfusion:SfDataGrid.Columns>
            <syncfusion:DataGridCheckBoxColumn MappingName="IsChecked" HeaderText="Checked" />
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>
</StackLayout>

C#:
To prevent the auto-generation of the helper property column (which is a member of the model class and will be replaced by the IsChecked column), you should disable the generation of the helper property column.

public static SampleDemoDatabase sampleDemoDatabase;
public static SampleDemoDatabase SampleDemoDatabase
{
    get
    {
        if (sampleDemoDatabase == null)
            sampleDemoDatabase = new SampleDemoDatabase();
        return sampleDemoDatabase;
    }
}
public MainPage()
{
    InitializeComponent();
    dataGrid.ItemsSource = SampleDemoDatabase.OrderItemsDataSource;


    
}

private void dataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    if (e.Column.MappingName == "Count")
    {
        e.Cancel = true;
    }
}

Model:
The code below illustrates how to use a helper property in the model class, which stores a value of 1 or 0 from the database. You can create a boolean property, IsChecked, in your model class that maps to this helper property (holding 0 or 1 values) for display in the DataGrid. If the IsChecked property is 1, the CheckBox will appear checked; if IsChecked is 0, the CheckBox will be unchecked.

public class OrderItem
{
    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }
    public int OrderID { get; set; }
    public string Name { get; set; }
    public int TokenNo { get; set; }
    public string BillStatus { get; set; }
    public int Count { get; set; }
    public bool IsChecked
    {
        get
        {
            return Count == 1 ? true : false;
        }
        set
        {
            Count = value ? 1 : 0;
        }
    }
}

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to display checkboxes with 0 and 1 values mapped from SQLite in a .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)
Access denied
Access denied