Get a NULL value in a textbox

  • Thread starter Thread starter Filip De Backer
  • Start date Start date
F

Filip De Backer

Hi,

When i delete the text of a textbox, the value is an
empty string. How can I get a NULL value in it. I know
that it is DBNull.Value, but how can I simple get this
value in the textbox when I delete the string in it?

Thanks for any answers

Filip
 
This might be more than you wanted to do, but you could
create a control that derives from Textbox.
Override/Shadow the Text property and return null if the
value is an empty string.

public class MyTextBox : System.Windows.Forms.TextBox
{
public new string Text
{
get
{
if(base.Text.Trim().Length == 0)
return(null);
else
return(base.Text);
}
set{base.Text = value;}
}
}
 
Back
Top