Value of the first cell of the selected row datagridview

0

Friends, good night. I'm having trouble handling the data in a datagridview, I need to assign the value of the cell to the first column of the row the user selected when the user clicks the row.

Then I created an Event of type SelectionChanged, within that event it includes:

 private void clik_table_cliente(object sender, EventArgs e)
    {
        // vamos obter a linha da célula selecionada
        DataGridViewRow linhaAtual = dataGridView1.CurrentRow;

        // vamos exibir o índice da linha atual
        int indice = linhaAtual.Index;
        MessageBox.Show("O índice da linha atual é: " + indice);
    }

I can know which line is selected, but now how do I assign the value of the cell in the first column of this line?

Thanks for the help.

    
asked by anonymous 27.06.2016 / 06:09

1 answer

1

Hello, you already have the selected line , and you already know which column you want to update, so it's simple.

Access the row collection through the Rows property, and from the row you want to access the collection of cells (columns) through Cells . Choosing the desired cell uses the Value property to set the value. So:

// configurando valor da primeira coluna, índice 0
dataGridView1.Rows[indice].Cells[0].Value = "meuValorAqui";
    
27.06.2016 / 12:53