Set variable in form designer

Asked

Viewed 77 times

0

How can I set a variable in a form designer?

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

The variable 'id_grid' is either undeclared or was Never Assigned.

Follows 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");

1 answer

2


First, you should not move the self-generated code by Visual Studio (basically, the method InitializeComponent that is in partial .Designer). If you open this partial you will see that in 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 was done when going through the form design, after all this file will be edited by the IDE.

Aside from that, you will probably break the design of your form. Hence the warning

The variable 'id_grid' is either undeclared or was Never Assigned.

Without more details about what you’re trying to do, it’s hard to know, but I can’t see a real reason to put this code in the partial designer. I can give you two tips to fix this:

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

    public Form()
    {
        InitializeComponent();
        OutroInicializadorDeComponentes();
    }
    
  2. Try to create another method inside the partial designer, I’m not sure it will work, but I think so since Visual Studio only puts warning not to mess with the method InitializeComponent.


Obs.:

  • You can see this answer to understand what is and what serves a partial class.
  • Good afternoon friend, thanks for telling me. I will study your tips, I opened a question on MSDN and it contains photos, if you can take a look, I would be very grateful. https://social.msdn.microsoft.com/Forums/pt-BR/b831a788-10e9-4378-a260-f8a9b68ff4d3/gridcontrol-com-where-idcliente-idcliente?forum=vscsharppt

  • 3

    @Thomaserichpimentel I think it’s kind of weird someone being on a site specializing in Q&A trying to get users to answer their questions in a forum.

  • 1

    @Thomaserichpimentel I see no reason to see your post on MSDN. I already answered here...

  • Perfect.Thank you..

  • 1

    @Thomaserichpimentel remembering that if you have other questions that need image, you can open the questions here at Sopt and insert the images in the post without problems. It is only important to note that if it is code, or even error messages, you should put the source in text itself, which is easier to read, and copy and paste for tests and searches. Here are some formatting tips, and the post toolbar already has the comic icon for inserting images, and the icon { } for formatting code. This text also has some good tips for valuing the text: [Ask].

  • Buddy, good afternoon. perfect, I’ll give a read on formatting and watch me when post any questions. Thanks

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.