How to leave a Datagridbview column invisible to the user

0

Good afternoon. I have a theme in C # which contains a datagridviwer, and I am populating this direct datagridiview with a database query, but it has a column that needs to be in the select, but I can not show the user in the datagridiview, how can I leave this column invisible. The column [Solical Number] must be invisible to the user.

The code that populates the datagridview follows.

 private void ListaGrid()
        {
            string strSQL = @"select distinct 
                           pro.Cod_Produto as CODIGO,
                           pro.NomeProduto as PRODUTO,
                           pro.Lote as LOTE,
                           pro.Fabricante AS REPRESENTADA,
                           pro.Qtda as QTDA,
                           sa.Id_Solicitacao AS [N° Solic.]
                      from tbl_SolicitacaoAmostra as sa
                      inner join tbl_Produto as pro with (nolock) on pro.Id_Solicitacao = sa.Id_Solicitacao
                      where sa.Cod_Solictacao = '" + txt_numero.Text + "'";

            comando = new SqlCommand(strSQL, conex1);

            try
            {
                SqlDataAdapter dados = new SqlDataAdapter(comando);
                DataTable dtLista = new DataTable();
                dados.Fill(dtLista);

                DGW_itens.DataSource = dtLista;
            }
            catch
            {
                MessageBox.Show("Não existem dados a serem encontrados");
            }
        }
    
asked by anonymous 11.09.2017 / 19:00

1 answer

0

With what you have so far, what you can do is change the visibility of the column after filling the grid

Something like this:

DGW_itens.Columns[0].Visible = false;

Where 0 matches the index you want to hide.

Or

DGW_itens.Columns["Nome da Coluna"].Visible = false;

Where Column Name is the name produced in the select.

    
11.09.2017 / 19:31