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:

Created:

Updated:

Platform:

Replies:

77361 Oct 28,2008 06:49 PM UTC Nov 2,2008 09:04 PM UTC WinForms 3
loading
Tags: GridControl
abc
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?

-TC


abc
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?

-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



Rajadurai C [Syncfusion]
Replied On 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


abc
Replied On November 2, 2008 09:04 PM UTC

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

-TC


CONFIRMATION

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.

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

;