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. Image for the cookie policy date
close icon

GridDataboundGrid: problems with binding business-objects with nullable types

Hi

We use the GridDataboundGrid and we have encountered a problem when binding businessobjects that have nullable properties (such as float?)

To add a new object, one normally just has to enter the values into the cells of the last (and empty) row. Upon the loosing the focus of that row, a new business object is created and added to the bound list. Usually, the user has to enter data in most cells, but in some cases null values are allowed.

However, this does not work, as a null value (of the cellvalue property) prevents the business object from being added.
(By the way: I experimented a bit with custom cells models and renderers and I have found out that the method OnRejectChanges of the renderer is being called but I have not found any event or overriden method where I can prevent this)


So my question is:

- What do I have to do to make the GridDataBoundGrid work with custom objects and nullable types. A custom objects needs to be created even when the nullable types columns are not set.

(to be more specific:
- is there a simple property of the column (styleinfo) to be set?)
- if not, is there an event in an custom cell model/renderer class that i can use?

Thanks in advance

Dan

15 Replies

NR Nirmal Raja Syncfusion Team August 11, 2010 08:54 AM UTC

Hi Dan,

Thank you for your interest in Syncfusion products.

If the cell needs to accept the null values from the source then you have to set the AllowDBNull to true for each column of the grid.

Please refer to the code below:
(this.gridDataBoundGrid1.DataSource as DataTable).Columns[0].AllowDBNull = true;

Let me know if you have any concern.

Regards,
Nirmal


DK Dani Knopf August 12, 2010 05:46 AM UTC

Hi

Thanks for your answer. Unfortunately, we use busines objects (from the entity framework) not a dataTable, so your solution does not apply.

What do I have to do to make the GridDataboundGrid work when the business objects have nullable properties (such as float?, short?)

Thanks


JJ Jisha Joy Syncfusion Team August 13, 2010 12:31 PM UTC

Hi Dani,

As long as the the underlying datasource supports nullable values, GridDataBound will allow null value to the cells. Can you please provide us a small sample shaowing the issue?. So that we could analyze it and provide you a solution based on it.

Regards,
Jisha


DK Dani Knopf August 15, 2010 12:15 PM UTC

Hi

Attached a solution where the issue is reproducable. It may have something to do that we use entity objects that are attached to the context and not custom busines objects. I haven't been able to reproduce the issue with normal business objects.

Furthermore I found out, that it not only has something to do with nullable types but also with the dropdown showing the different types of enumerations.

Here is how to reproduce the issue with the attached solution:

1. Cursor is on name field: enter a name
2. Enter "Tab" to go to the next dropdown field -> move further to the next field via tab (the dropdown chooses the first entry in its datasource)
3. Click on the a field in another row. Normally, a new row should be added but this does not happen. (With our extended custom grid class-> the row should appear pink. Please also see the method CustomGrid.GetBoundObject(int rowIndex) that returns null in this case where it should return the newly added object.

Strangly, it works when i choose a value in the dropdown via mouse click or i enter a value in all nullable fields (such as float?).. Very strange to me.


Thanks in advance and greetings

Dan




PS: please dont mind some custom code in the CustomGrid class (inheriting from the GridDataboundGrid). Most of it does not yet work and does not influence the issue.



TestGridExtensions_2b008148.rar


DK Dani Knopf August 19, 2010 06:37 AM UTC

Hi

Have you found the time to have a look at the issue?

Regards

Dan


JJ Jisha Joy Syncfusion Team August 19, 2010 11:29 AM UTC

Hi Dan,

Sorry for the delay in getting back to you. It seems that the edmx file provided in the sample seems to be corrupted. I was unable to run the sample. Could you please provide a sample that run without any errors.

Regards,
Jisha


DK Dani Knopf August 19, 2010 01:58 PM UTC

Hi

Hopefully this time it works. (I tried the first upload and it work on my machine, maybe it has something to do with the version. I use Visual Studio 2010 Professional, .Net 4.0)

Greetings

Dan



TestGridExtensions_39d12ad1.rar


DK Dani Knopf August 23, 2010 09:51 AM UTC

Hi

Have you been able to use the second upload?

Greetings

Dan


JJ Jisha Joy Syncfusion Team August 24, 2010 11:57 AM UTC

Hi Dan,

Sorry for the delay in getting back to you. Still I am not able to run the provided sample, it throws exceptions. Is it possible for you to provide a simple sample showing the issue?.

Regards,
Jisha


DK Dani Knopf August 24, 2010 12:32 PM UTC

Hi

The path in the "App.config" to the database was fixed not relative. Probably, this was the cause for your exception. I have changed it now and it should work.

If not, can you tell me more about the type of exceptions? Unfortunately, the example needs a (embedded) database because I suspect the issue to be related to the entity framework.

Greetings and thanks in advance.

Dan



TestGridExtensions_eae8aa8.rar


JJ Jisha Joy Syncfusion Team August 26, 2010 07:13 AM UTC

Hi Dan,

Please follow up with your direct trac incident 71412 for the same query.

Regards,
Jisha


DK Dani Knopf September 1, 2010 06:13 AM UTC

Thanks to the support, i could resolve the issue. I had to insert the following code:

//in FinalInitGrid() method
this.customGrid1.Binder.DefaultCurrentRecordItemChangedBehavior = GridCurrentRecordItemChangedBehavior.KeepCurrentRecord;

Greetings





CI Christopher Issac Sunder K Syncfusion Team September 2, 2010 03:51 AM UTC

Hi Dan,

Thanks for the update.

Glad to know that issue got resolved on your side.

Thank you for using Syncfusion products.

Regards,
Christo.




HS Hassaan Sohail replied to Dani Knopf March 6, 2018 10:00 AM UTC

Hi

Hopefully this time it works. (I tried the first upload and it work on my machine, maybe it has something to do with the version. I use Visual Studio 2010 Professional, .Net 4.0)

Greetings

Dan



TestGridExtensions_39d12ad1.rar

yes


SN Sindhu Nagarajan Syncfusion Team March 7, 2018 11:40 AM UTC

Hi Dan, 
  
Please let us know whether you need any technical assistance. 
  
Regards, 
Sindhu  


Loader.
Live Chat Icon For mobile
Up arrow icon