views:

249

answers:

0

Hello,

I am currently coding a project under c# and am experiencing problems. I'll give a brief description of my form:

It has a datagridview on the bottom half of the form with single row selection, and is read only. On the top half of the form I have various components which are databound to the selected row on the datagridview. I did this because there was too many columns in the database to show in the datagridview without seriously cluttering up the UI. This is working fine and the format and parse events are being called correctly.

I have a Add New Record button which rebinds the controls on the top half to a new datarow (which isn't part of the datatable yet) and this is where I'm having problems. Firstly when binding directly to a datarow it seems the controls arn't as happy with DBNull values as they are when binding to a datatable. But that's fine I just assigned default values to the new row before binding it. However, it seems the Format and Parse events are not fired when bound directly to a row for some reason, and I can't work out why? The main reason I need these is I have a Date value column which ideally needs to be null (blank from a UI perspective) so I assign the DateTime.MinValue as a default value on the new row and then I look for this on the format / parse event and do the nessessary convertions.

I guess my main question is why does binding to a datarow raise DBNull exceptions when binding to a datatable with the same null values in the same columns raises no exception and the column constraints has 'Allow Nulls'. My alternative question is why aren't the Format / Parse events fired when a component is bound to a datarow?