How to make a Datagridbview column invisible to the user

Asked

Viewed 387 times

0

Good afternoon. I have a c# theme that contains a datagridviwer, and I am populating this datagridiview directly with a database query, but it has a column that needs to be in select, but I cannot show the user in datagridiview, how can I make this column invisible. The column [N° Solic. ] has to be invisible to the user.

follows the code that populates the datagridview.

 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");
            }
        }
  • You set the columns beforehand (by the designer)?

  • So do not set no, mount straight when I read the query it already shows the columns according to the names I put in the query.

1 answer

0


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

Something like that:

DGW_itens.Columns[0].Visible = false;

Where 0 corresponds to the index you want to hide.

Or

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

Where Column name is the name produced in select.

  • Perfect LINQ was just what I was needing, thank you very much.

Browser other questions tagged

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