In my sfDataGrid, I am displaying a FirstName, LastName and BirthDate.
Here is my xaml for the DataGrid
<syncfusion:SfDataGrid x:Name="patientDataGrid" Grid.Row="0" Grid.RowSpan="5" Grid.Column="0" Grid.ColumnSpan="1" RowHeight="25"
SelectedIndex="{Binding DataGridSelectedIndex}"
SelectionChanged="dataGrid_SelectionChanged"
AutoGenerateColumnsMode="None"
ColumnWidthMode="Fill" SelectionMode="Single">
<syncfusion:SfDataGrid.DefaultStyle>
<syncfusion:DataGridStyle HeaderRowBackground="#512bd4" HeaderRowTextColor="White" RowBackground="#AFD5FB" RowTextColor="#212121" />
</syncfusion:SfDataGrid.DefaultStyle>
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn HeaderText="First"
MappingName="FirstName" />
<syncfusion:DataGridTextColumn HeaderText="Last"
MappingName="LastName" />
<syncfusion:DataGridTextColumn HeaderText="DOB"
MappingName="BirthDate" Format="MM/dd/yyyy" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
When I select a row in the Grid, a Data Form is opened with the date displayed as "1/1/1923"
Here is the Grid and Data Form.
My SQLite Table has the correct data represented correctly.
Can you provide a explanation/solution?
Thanks in advance.
Kartthik,
Even before showing the date field on the DataForm, the the display of the date on the sfDataGrid is incorrect. It shows "01/01/0001" .
Here are my details.
public DateTime BirthDate { get; set; }
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn HeaderText="First"
MappingName="FirstName" />
<syncfusion:DataGridTextColumn HeaderText="Last"
MappingName="LastName" />
<syncfusion:DataGridDateColumn HeaderText="DOB"
MappingName="BirthDate" Format="yyyy-MM-dd" />
</syncfusion:SfDataGrid.Columns>
This problem happens when the date data is pulled from a SQLite db.
If I use similar data that is generated in the app and not stored in a db, but loaded directly into a List and use the List as and an "itemsource" for the sfDataGrid, the date data is rendered correctly.
using EMRON8.Models;
using System.Reflection;
namespace EMRON8.Views;
public partial class MainPage : ContentPage
{
public static ObservableCollection<Patient> PatientList = new ObservableCollection<Patient>();
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
PatientRepository pat = new PatientRepository();
var patlist = pat.GetPatients();
foreach (var item in patlist)
{
PatientList.Add(item);
}
int patcount = patlist.Count();
patientDataGrid.ItemsSource = PatientList;
/// Does not work when using a SQLite database
///
//var dates = pat.GetDates();
//TestGrid.ItemsSource = dates;
/// does work when getting from the GetSampleData() method
///
TestGrid.ItemsSource = GetSampleData();
}
private void dataGrid_SelectionChanged(object sender, Syncfusion.Maui.DataGrid.DataGridSelectionChangedEventArgs e)
{
}
// Sample method to generate data
private static List<DataItem> GetSampleData()
{
List<DataItem> data = new List<DataItem>()
{
new DataItem() { Date = new DateTime(2023, 6, 15) },
new DataItem() { Date = new DateTime(2023, 6, 16) },
new DataItem() { Date = new DateTime(2023, 6, 17) }
};
return data;
}
}
public class DataItem
{
public DateTime Date { get; set; }
}
public class TestClass
{
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public DateTime DOB { get; set; }
}
Hi Frederick,
We have tested a simple sample and found that it didn't work. The issue seems to be in the framework itself as the SQLite doesn’t support for DateTime type . We have reported this issue to the MAUI framework team.
https://github.com/dotnet/maui/issues/15701
We will wait until the Framework team responses. We will do the action plan from our end based on the update from the framework team. We appreciate your patience and understanding in the meantime. Please let us know if you need any further assistance with this. As always, we are happy to help you out.
Regards,
Nirmalkumar