Interpret empty datagrid cells as empty strings

  • Thread starter Thread starter Thomas Berg
  • Start date Start date
T

Thomas Berg

When I clear a cell in a datagrid, the corresponding (string) field in the
underlying datatable becomes null.
I would prefer that it be an empty string, as the corresponding database
field is not nullable.
Does anyone have any tips as to how to accomplish this?

Thomas Berg
 
H

Instead of clearing the cell set its value to String.Empty this represents a zero-length string, ""

Hope this will solve your issue

Regard

Sooraj P
Microsoft India Community Star
 
I should have been clearer. When I say "clear a cell", I
mean the user puts the cursor in the cell and deletes all
the text there. Were you thinking I meant I clear it in code?

If you did understand what I intended, then I don't think I
understand your answer. In particular, WHEN do I set the
value to an empty string? As far as I know the datagrid
doesn't raise any events on data modification. I suppose I
could catch each datatable's RowChanged event, scan the
row for nulls I don't want, and set them to empty strings there.
But if that's the best way to do it in VB, I'd rather rewrite my
stored procedures to convert nulls to empty strings.

What I had hoped is for some setting I can make to the
DataColumn (ideally in the DataSet Designer) telling it how to
interpret a blank. Or perhaps a property on the DataGrid's
columnstyle makes more sense. Is there anything like that?
The DataSet designer offers a 'NullValue' property, but I
haven't seen any effect from setting it.

Thomas Berg
 
Back
Top