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

Proper way to handle null values?

I have a GridDataBoundGrid with a bound ComboBox column. How do I properly deal with null values? I''d like to show the string "- Choose -" if the the value is null. I''d also like to store the value of null if nothing is chosen. The only NullString property I could find for a column was under StyleInfo.CurrencyEdit.NullText. I tried setting the NullString value, but this didn''t seem to work. The null value cell still turns red. Also, on an unrelated note, is there an advanced search for these forums? It seems to treat my search text as a phrase instead of independant keywords. I''m sure most of my questions are answered somewhere in the forums, I just have a hard time finding them. Thanks, Daws

8 Replies

AD Administrator Syncfusion Team March 25, 2004 04:05 PM UTC

The 2030 version of the grid will handle and preserve null values in combobox cells without any additional work, showing an empty cell. But if you want to display some special text in this null case, then you can handle grid.Model.QueryFormattedCellText and manage things there. Here is a sample. forum12286_9274.zip


DA Daws March 25, 2004 04:28 PM UTC

What is the release schedule for the new grid? I can''t recommend that my clients use a beta version in their product. Alternatively, what is the "hard" way to accomplish my original question with the current version of the grid? Thanks, Daws


AD Administrator Syncfusion Team March 25, 2004 04:50 PM UTC

Hi Daws, What kind of datasource do you use? What we made with datasets/datatables: add the neutral row and merge the values to the table. Regards Thomas


AD Administrator Syncfusion Team March 25, 2004 05:14 PM UTC

What version are you using? The sample worked unchanged for me in 1618 as well. That is a release version that you can download from your Direct Trac home page.


DA Daws March 25, 2004 05:43 PM UTC

Thanks Clay. You are right again. I didn''t try the sample since I assumed it was for the new version of the grid. Thanks, Daws


DA Daws March 25, 2004 05:45 PM UTC

I re-read your original answer and now I understand that your sample was for the current version of the grid. Sorry for the confusion. Thanks, Daws


DA Daws March 25, 2004 06:48 PM UTC

Okay, I still have a problem. Your sample is using a datasource that is a DataTable. The null values you have in there are actually System.DBNull values. I''m using an IBindingList datasource and the values returned are acutal null values. The effect of this is that I am getting the following exception in the debug output prior to entering the QueryFormattedCellText event handler: System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Windows.Forms.Grid.GridStaticCellRenderer.OnDraw(Graphics g, Rectangle clientRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridTextBoxCellRenderer.OnDraw(Graphics g, Rectangle clientRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridStaticCellRenderer.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.OnDrawItem(Graphics g, Int32 rowIndex, Int32 colIndex, Rectangle rectItem, GridStyleInfo style) catched at Syncfusion.Windows.Forms.Grid.GridControlBase.OnDrawItem(Graphics g, Int32 rowIndex, Int32 colIndex, Rectangle rectItem, GridStyleInfo style) in :line 0 Is there another event that I can handle prior to this exception being thrown? This exception is never thrown in the sample that you posted. Thanks, Daws


DA Daws March 25, 2004 07:44 PM UTC

Okay, I have found a solution... I translate the null value into a DBNull value in the QueryCellInfo handler, then I do the reverse translation in the SaveCellInfo handler. I can still use the sample provided to change the DBNull text. Regards, Daws

Loader.
Live Chat Icon For mobile
Up arrow icon