Dear,
I
You have given a nice example which is exactly I have done in application. you can face my narrated problem even in your coding.
I have attached here a video. here when I start application, it loads some of data grid rows in datagrid. Now in 3rd row IsPK coulmn is not checked. I checked it and then pressed AddRow button.
You can see that on clicking AddRow button, the checked cell in 3rd Row will get again unchecke. Same thing I repeated for 6th row.
Why checked cell gets unchecked on adding new row? and how to get get checked cell value to save in data.
Please check and revert.
Thanking you.
|
private async void dataGrid_ValueChanged(object sender, Syncfusion.SfDataGrid.XForms.ValueChangedEventArgs e)
{
viewModel.DataTable.Rows[e.RowColumnIndex.RowIndex - 1][e.RowColumnIndex.ColumnIndex] = e.NewValue;
viewModel.DataTable.AcceptChanges();
var items = await viewModel.Database.GetItemsAsync();
for(int i=0;i<items.Count;i++)
{
var item = items[i];
if ((e.RowColumnIndex.RowIndex-1) == i)
{
if (e.Column.MappingName == "IsChecked")
{
item.IsChecked = (bool)e.NewValue;
}
else if(e.Column.MappingName== "IsPK")
{
item.IsPK = (bool)e.NewValue;
}
await viewModel.Database.UpdateItemAsync(item);
break;
}
}
} |
Dear,
I am using data table as datasource in sfdatagrid. I have some boolean column. so I converted it to switch column using
e.Column = new GridSwitchColumn { MappingName = MapName, TextAlignment = TextAlignment.Center, Padding = 5 };
On linking datatable as datasource, I get 2 records from database, in attached image - Check1.png, you can see that in 1st row IsPK column is auto checked because in SQL database it is 0 in bit datatype.
Now I checked IsFk field. you can see in same image. Now I added new row clicking Add button using following code:
private void BtnAddRow_Clicked(object sender, EventArgs e)
{
//this.dataGrid.UnboundRows.Add(new GridUnboundRow() { Position = UnboundRowsPosition.Bottom });
//this.dataGrid.QueryUnboundRow += DataGrid_QueryUnboundRow;
//dt.Rows.Add();
//dataGrid.AutoGenerateColumns = false;
//dataGrid.ItemsSource = dt;
dataGrid.View.AddNew();
dataGrid.View.CommitNew();
}
But on adding new row, new row added in datagrid but the checked column IsFK gets unchecked which was previously checked. You can see image Check2.png.
I debugged and analyzed that the value true to false or false to true did not updated. So please let me know how to solve this problem.