-2

I m trying to make a method and call it everytime I want my textboxes to go blank in my form.

The code I ve tried is listed below

In the main(form) code:

 _BlankSpaces.NineBlankTextboxes( ref txtSup.Text, ref txtSupName.Text, ref txtSupCode.Text, ref txtZenonName.Text, ref txtZenonCode.Text, ref txtInAmount.Text, ref Combo_Mech_El.Text, ref txtDescr.Text, ref txtID.Text);

                    /*   Instead of:
                    txtSup.Text = "";
                    txtSupName.Text = "";
                    txtSupCode.Text = "";
                    txtZenonName.Text = "";
                    txtZenonCode.Text = "";
                    txtInAmount.Text = "";
                    Combo_Mech_El.Text = "";
                    txtDescr.Text = "";
                    txtID.Text = ""; */

                    //And In the Class I call:

namespace WarehouseManagementToolv1.Secondary
{
    public class BlankSpaces
    {

        //public string Blank1, Blank2, Blank3, Blank4, Blank5, Blank6, Blank7, Blank8, Blank9;

        public void NineBlankTextboxes(ref string blank1, ref string blank2, ref string blank3, ref string blank4,
            ref string blank5, ref string blank6, ref string blank7, ref string blank8, ref string blank9)
        {
            blank1 = "";
            blank2 = "";
            blank3 = "";
            blank4 = "";
            blank5 = "";
            blank6 = "";
            blank7 = "";
            blank8 = "";
            blank9 = "";

        }

    }
}

When I run it the massage I get is:

A property or indexer may not be passed as an out or ref parameter

Property "Text" access returns temporary value. "ref" argument must be an assignable variable, field or an array element.

lczapski
  • 4,026
  • 3
  • 16
  • 32
  • 2
    Possible duplicate of [A property or indexer may not be passed as an out or ref parameter](https://stackoverflow.com/questions/4518956/a-property-or-indexer-may-not-be-passed-as-an-out-or-ref-parameter) – Joakim Skoog Oct 29 '19 at 13:14

2 Answers2

0

this is only possible with jquery or css selectors (web app), for C# (desktop app) this is not possible, you should clear your text using yourtext.Text = string.Empty , or by binding a property and set it to empty each time you want to.

Erwin Draconis
  • 764
  • 8
  • 20
0

You could try something like

private void ClearTextBoxes(params TextBox[] list)
{
    foreach(TextBox tb in list)
    {
        tb.Text = "";
    }
}

This would be used as

ClearTextBoxes(txtSup, txtSupName, txtSupCode); // TODO : Add any other textboxes

This sidesteps the issue of trying to send a reference copy of a property and sends the object itself to allow it to be cleared.

Kami
  • 19,134
  • 4
  • 51
  • 63