checked datagrid column unchecked on adding new row - xamarin form

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.

 



Attachment: checkbox_c8d886eb.zip

3 Replies

SV Suja Venkatesan Syncfusion Team February 11, 2022 01:55 PM UTC

Hi Amish, 

We have updated the response in your reported ticket which is related to same as mentioned issue. Please have a follow up in that ticket for further updates. 

Regards, 
Suja 




AM Amish replied to Suja Venkatesan February 12, 2022 04:46 AM UTC

Dear,

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.     



Attachment: 100349_937286fa.zip


SV Suja Venkatesan Syncfusion Team February 14, 2022 02:33 PM UTC

Hi Amish, 

Once the value has been changed at runtime, you must update the Datatable and Database. You can resolve the reported issue by updating the item value in Database and DataTable by handling the SfDataGrid.ValueChanged event as like below code snippet. 

Code Snippet: 
  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; 
                } 
            } 
        } 

Please refer the below sample for your reference.  

Please refer our user guidelines documentation regarding ValueChanged event of SfDataGrid in the below link. 

Please let us know if you need any further assistance. 

Regards, 
Suja 


Loader.
Up arrow icon