How to perform event with instantiated class in another method

Asked

Viewed 26 times

1

I have a method that triggers a "Bandedgridview" :

 private void popula_retContrato(string contrato)
    {
        Classes.Datatable.Datatable_cliContrato dat_contrato = new Classes.Datatable.Datatable_cliContrato();

        gridControl4.Visible = true;

        DataSet set = new DataSet();

        set = dat_contrato.contrato_set(contrato);

        gridControl4.DataSource = set.Tables["contratos"];
        gridControl4.ForceInitialize();

        GridBand tag = new GridBand() { Caption = "Sumário" };

        BandedGridView bandgridview4 = new BandedGridView(gridControl4);

        bandgridview4.Bands.Add(tag);

        gridControl4.LevelTree.Nodes.Add("relator", bandgridview4);

        bandgridview4.ViewCaption = "Relatórios";
        bandgridview4.PopulateColumns(set.Tables["relatorios"]);

        format_grid_contrato();
        format_subgrid_contrato(bandgridview4);
    }

I need to use this instance BandedGridView at an event:

private void click_datagridview4(object sender, EventArgs e)
    {
        id_etiqueta = Convert.ToInt32(bandgridview4.GetRowCellValue(bandgridview4.GetSelectedRows()[0], "Nº"));

        MessageBox.Show("valor id_etiqueta " + id_etiqueta);
    }

But when using the above code is generated error:

inserir a descrição da imagem aqui

How could I accomplish this?

1 answer

0


I was able to solve it this way:

private void click_datagridview4(object sender, EventArgs e)
    {
        BandedGridView bandgridview4 = (BandedGridView)sender;

        id_etiqueta = Convert.ToInt32(bandgridview4.GetRowCellValue(bandgridview4.GetSelectedRows()[0], "Nº"));
    }

Browser other questions tagged

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