The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
When I clear the value in a grid cell, the grid saves an empty string, not DBNull, to the bound DataTable. For this DataTable, that behavior is incorrect. How do I fix it?
I solved this with some code that edits the data source in response to the RowSaved event. However, I'm not satisfied with this solution. Since handling Null values is such an integral part of data management, I suspect the GridDataBoundGrid has a more elegant way of dealing with the problem. Does it?
-TC
Private Sub MyGrid_RowSaved(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridRowEventArgs) Handles MyGrid.RowSaved
Dim MyDataTable As DataTable Dim MyDataColumn As DataColumn
'Find the DataTable associated with the grid. MyDataTable = CType(MyGrid.DataSource, DataTable)
'Work with the DataRow associated with the grid row. With MyDataTable.Rows(MyGrid.Binder.RowIndexToListManagerPosition(e.RowIndex))
'Loop through all columns. For Each MyDataColumn In MyDataTable.Columns
'If the column contains an empty string, convert it to a Null value. If Object.Equals(.Item(MyDataColumn), "") Then .BeginEdit() .Item(MyDataColumn) = DBNull.Value .EndEdit() End If
Next
End With
End Sub
RCRajadurai C Syncfusion Team November 1, 2008 05:52 AM UTC
Hi,
Thanks for your interest in Syncfusion products.
Apologies for the delay.
Glad to hear that you solved the issue by means of RowSaved eventhandler.
To simplify code, you can make use of CurrentCellValidating eventhandler.
Please refer the following code: private void gridDataBoundGrid1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; if(cc.ColIndex == 2) //column which is to be checked for empty { string val = cc.Renderer.ControlText; if(val.Length == 0) { //code to update the datasource } } }
Please let us know if this helps.
Regards, Rajadurai
ABabcNovember 2, 2008 09:04 PM UTC
Yes, that helps. Thank you for the excellent support.