We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I make a GridDataBoundGrid use DBNull, not an empty string?

Thread ID:





77361 Oct 28,2008 06:49 PM UTC Nov 2,2008 09:04 PM UTC WinForms 3
Tags: GridControl
Asked On October 28, 2008 06:49 PM UTC

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?


Replied On October 30, 2008 07:13 PM UTC

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?


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
.Item(MyDataColumn) = DBNull.Value
End If


End With

End Sub

Rajadurai C [Syncfusion]
Replied On November 1, 2008 05:52 AM UTC


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.


Replied On November 2, 2008 09:04 PM UTC

Yes, that helps. Thank you for the excellent support.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon