SfDataGrid sorting breaks when cancelling Add New Row, with a Dictionary ValueBinding

I'm using the SfDataGrid with GridNumericColumn and ValueBinding to be able to handle uint values properly. The number of columns is variable, so the columns are created in code with a Dictionary<int, object> as the binding source. The ValueBinding is needed because I need to be sure that the Dictionary's value (of type Object) is only ever set to uint values.

var col1 = new GridNumericColumn { NumberDecimalDigits = 0, ParsingMode = ParseMode.Int };
col1.ValueBinding = new Binding($"Columns[0]") {
Converter = new NumericUInt32ColumnValueConverter()
};
col1.MappingName = "Columns[0]";
col1.HeaderText = "Col 0";
col1.UseBindingValue = true;
this.DataSetDataGrid.Columns.Add(col1);

This seems to work fine; values are displayed correctly and can be edited correctly, and sorting works. However, when clicking into the Add New Row area at the top of the grid, then pressing Escape once to exit edit mode of the cell, and then pressing Escape a second time to exit edit mode of the row, the sorting for the first column no longer works. If you click the first column header to change the sort order, nothing changes. Sorting of the second column still seems to work.

I've attached the code needed to reproduce this issue. You just have to try clicking the first column header to verify that it sorts correctly, click into the Add New Row area, press Escape twice, then try to sort the first column header again.

Am I doing something wrong here, or is this a bug that can be fixed?


Attachment: Syncfusion_DataGrid_Test_a8d9c926.zip

3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team August 24, 2022 02:52 PM UTC

Hi Mark,

You can resolve the reported problem by setting the Mode as TwoWay in the ValueBinding property of GridColumn. Please refer to the below code snippet,

// Set up the columns.

var col1 = new GridNumericColumn { NumberDecimalDigits = 0, ParsingMode = ParseMode.Int };

col1.ValueBinding = new Binding($"Columns[0]") {

              Converter = new NumericUInt32ColumnValueConverter(),

              Mode = BindingMode.TwoWay

};

col1.MappingName = "Columns[0]";

col1.HeaderText = "Col 0";

col1.UseBindingValue = true;

this.DataSetDataGrid.Columns.Add(col1);

 

var col2 = new GridNumericColumn { NumberDecimalDigits = 0, ParsingMode = ParseMode.Int };

col2.ValueBinding = new Binding($"Columns[1]") {

              Converter = new NumericUInt32ColumnValueConverter(),

              Mode = BindingMode.TwoWay

};

col2.MappingName = "Columns[1]";

col2.HeaderText = "Col 1";

col2.UseBindingValue = true;

this.DataSetDataGrid.Columns.Add(col2);


Please find the modified sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: ModifiedSample_adc198b4.zip

Marked as answer

MA Mark August 24, 2022 03:07 PM UTC

Thanks, that works perfectly!



VS Vijayarasan Sivanandham Syncfusion Team August 25, 2022 06:13 AM UTC

Hi Mark,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,

Vijayarasan S


Loader.
Up arrow icon