Define variable in the form designer

0

How can I define a variable in the designer of a form?

Today I define the variable for my parameter, but when I see the form it gives this warning (even with the warning, it executes normally):

  

The variable 'id_grid' is either undeclared or never assigned.

Follow the code:

this.sqlDataSource1.ConnectionName = "String tpspoazsql01 onee";
this.sqlDataSource1.Name = "sqlDataSource1";
columnExpression15.ColumnName = "nome";
table3.MetaSerializable = "0|0|125|260";
table3.Name = "Cliente_enderecos_alter";
columnExpression15.Table = table3;
column15.Expression = columnExpression15;
columnExpression16.ColumnName = "endereco";
columnExpression16.Table = table3;
column16.Expression = columnExpression16;
columnExpression17.ColumnName = "numero";
columnExpression17.Table = table3;
column17.Expression = columnExpression17;
columnExpression18.ColumnName = "bairro";
columnExpression18.Table = table3;
column18.Expression = columnExpression18;
columnExpression19.ColumnName = "cidade";
columnExpression19.Table = table3;
column19.Expression = columnExpression19;
columnExpression20.ColumnName = "estado";
columnExpression20.Table = table3;
column20.Expression = columnExpression20;
columnExpression21.ColumnName = "cep";
columnExpression21.Table = table3;
column21.Expression = columnExpression21;
selectQuery3.Columns.Add(column15);
selectQuery3.Columns.Add(column16);
selectQuery3.Columns.Add(column17);
selectQuery3.Columns.Add(column18);
selectQuery3.Columns.Add(column19);
selectQuery3.Columns.Add(column20);
selectQuery3.Columns.Add(column21);
selectQuery3.FilterString = "[Cliente_enderecos_alter.id_cliente] = ?ID1";
selectQuery3.Name = "Cliente_enderecos_alter";

queryParameter5.Name = "ID1";
queryParameter5.Type = typeof(int);
queryParameter5.ValueInfo = "0";
  queryParameter5.Value = id_grid;
selectQuery3.Parameters.Add(queryParameter5);
selectQuery3.Tables.Add(table3);
this.sqlDataSource1.Queries.AddRange(new DevExpress.DataAccess.Sql.SqlQuery[] {
selectQuery3});
this.sqlDataSource1.ResultSchemaSerializable = resources.GetString("sqlDataSource1.ResultSchemaSerializable");
    
asked by anonymous 10.07.2016 / 18:00

1 answer

2

First, you should not tinker with self-generated code by Visual Studio (basically, the InitializeComponent method that is in partial .Designer ). If you open this partial you will see that in the summary of this method has the text below

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>

If you put your code in this method you have a great chance of losing what you did when you move the form design, after all this file will be edited by the IDE.

Outside that, you'll probably break your form's design. So the warning

  

The variable 'id_grid' is either undeclared or never assigned.

No more detail about what you're trying to do is hard to know, but I can not see a real reason to put this code in the partial designer. I can give you two tips to solve this:

  • Create a method in the other partial and call it in the constructor along with InitializeComponent . This will not separate your code in another file, but it is already much better than it is. Ex.:

    public Form()
    {
        InitializeComponent();
        OutroInicializadorDeComponentes();
    }
    
  • li>

    Note:

    • You can see this answer to understand what a partial class is and what it is for.
  • 10.07.2016 / 18:46