Pass data from one gridview to another gridview

Asked

Viewed 541 times

0

I have a datagridview1 that searches the database for the data and shows the information, I want to click the add button to take the selected line in the first datagridview1 and move to another datagridview2.

inserir a descrição da imagem aqui

  • 2

    How does the data Binding for the first Datagrid?

  • 'var source = new Bindingsource(); List<Data> Dataosbo.Getusuario(User.idUsuario); // Takes all user data. source.datasource = data; datagridview.datasource = source;'

  • Why not grab the click on the cell, check which ID of the Dado, search in the bank and feed a list that will serve as Binding for the second Datagrid?

1 answer

2

I put a List<string> just by example, but the idea is this:

    List<string> Selecionados = new List<string>();
    private void buttonAdicionar_Click(object sender, EventArgs e)
    {
        if (dataGridView1.SelectedRows.Count >0)
        {
            string item = dataGridView1.SelectedRows[0].Cells["ColunaItem"].Value.ToString();
            //Adiciona outras propriedades, quantidades, etc...
            Selecionados.Add(item);
            //update no dataGridView2
        }
    }

Browser other questions tagged

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