I am using the following code to check for a null text-box, and, if it is null, skip the copy to clipboard and move on to the rest of the code.
I don't understand why I am getting a "Value cannot be NULL" exception. Shouldn't it see the null and move on without copying to the clipboard?
private void button_Click(object sender, EventArgs e)
{
if (textBox_Results.Text != null) Clipboard.SetText(textBox_Results.Text);
//rest of the code goes here;
}
First declare emptyTextBoxes as the selection of any text property with length 0. then check if there is any textbox with length = 0 and show it.
foreach (Control c in this. Controls) { if (c is TextBox) { TextBox textBox = c as TextBox; if (textBox. Text == string. Empty) { // Text box is empty. // You COULD store information about this textbox is it's tag. } } }
You should probably be doing your check like this:
if (textBox_Results != null && !string.IsNullOrWhiteSpace(textBox_Results.Text))
Just an extra check so if textBox_Results
is ever null
you don't get a Null Reference Exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With