checkbox in datagridview

Asked

Viewed 605 times

-1

inserir a descrição da imagem aqui

I am developing an application in c# that makes impression of labels, for this to happen I use a datagridview, which brings the lines I need to print, now I need to put a checkbox to select the line I need to send to the printer.

I need to have the option to select all lines or select only one line, I’m having difficulty to create this condition within my code.

Follow the code on the print button.

private void btnImprimir_Click(object sender, EventArgs e)
{
        if (caixa_selecao.ShowDialog() == DialogResult.Cancel)
            return;
        else
            EtqFraciona.PrinterSettings = caixa_selecao.PrinterSettings;
        etqfrac();
    }
}

code that loads the datagridview

private void Listagrid() { string strSQL = @"SELECT SC.C2_NUM AS GUIA, SB.B1_DESC AS PRODUCT, SC.C2_XNPAIS [COUNTRY OF ORIGIN], CONVERT(VARCHAR(10), CAST( SC.C2_XDTFAB AS DATE),103) AS [DT. MANUFACTURING], CONVERT(VARCHAR(10), CAST( SC.C2_XDTVALI AS DATE),103) AS [DT. VALIDITY], SC.C2_XLOTEF AS [LT. FABRICANTE], SC.C2_XLOTE AS [LT. INTERNO], SB.B1_XDCB AS DCB, SB.B1_XCAS AS CAS, CONVERT(VARCHAR(10),CAST(SB.B1_PESO AS NUMERIC(15, 3))) + SB.B1_XSEGUM AS WEIGHT, SC.C2_XNOMFA AS MANUFACTURER, CB.CB0_CODETI AS [COD. BARS] FROM SC2020 AS SC INNER JOIN SB1020 AS SB WITH (NOLOCK) ON SB.B1_COD = SC.C2_PRODUTO INNER JOIN CB0020 AS CB WITH (NOLOCK) ON CB.CB0_LOTE = SC.C2_XLOTE WHERE C2_NUM = '" + txtGuiaFrac.Text + "'";

        comando = new SqlCommand(strSQL, conex);

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

            DGW_EtqFracionamento.DataSource = dtLista;
        }
        catch
        {
            MessageBox.Show("Não existem dados a serem encontrados");
        }

    }

Now the checkbox column in datagridview I added by the property of datagridview in add columns.

  • Friend, would be? Winforms? Asp.Net? be more specific, you want to put the CheckBox only in printing (report)? or before? and only print what you have with Checked == true?

  • Thanks for the attention, and windows form, but do not use reportvierw no, use the printdocument to make the impression, only I am not able to create in datagridview chekbox, if I need to put the rest of my code.

  • friend, you want to do two different things, first add a column to the Grid, I think this answers your question: https://stackoverflow.com/questions/3061103/how-to-add-the-checkbox-to-the-datagridview-coding 2º Print only what is selected right?

  • That’s right Thomas, print what’s selected.

  • Thomas then if you notice the image above on my screen in the select field I added the chekbox in the datagridview so that does not appear the little square to make the tick.

  • places code for gridview and checkbox

  • I already put the code of datagrideview, but the code of chekbox did not do because there is my difficulty.

Show 2 more comments

1 answer

0


Try to follow these steps, I believe it will help you.

  • Select your Datagridview within the Form.
  • Select the Datagridview Smart-Tag according to the image. inserir a descrição da imagem aqui

  • When selecting appear the following options, select what is marked: inserir a descrição da imagem aqui

  • A new window will appear according to the image with all possible options for you to customize your Datagridview. Already in yours is to put a checkbox for each option. Then you do the following, follow the sequence of images:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui Note that there are Name and Header Text properties. Name - will be the NAME given to column

Header Text - will be the COLUMN TITLE that will be displayed in Datagridview.

inserir a descrição da imagem aqui Press ADD

At the end, you will return the previous screen, and the column you created. If you select the column you change the position of the column through the arrows that is on the right side.

At last press OK

AND YOUR DATAGRIDVIEW WILL GET THE RESULT SIMILAR TO THIS:

inserir a descrição da imagem aqui

I hope I’ve helped.

  • Okay gave right here, thank you very much.

Browser other questions tagged

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