Value of the first cell of the selected line datagridview

Asked

Viewed 4,546 times

0

Friends good night. I am having difficulties in processing the data of a datagridview, I need that when the user clicks on the line, it is assigned to a variable, the value of the cell, of the first column of the line that the user selected.

So I created an event of the type Selectionchanged, within that event 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 row is selected, but now, how to assign the value of the cell, the first column of that row?

Thanks for the help.

1 answer

1


Hello, you already have the selected line, and you already know which spine who wants to update, so it’s simple.

Access the line collection through the property Rows, and from the desired row access the collection of cells (columns) through Cells. Choosing the desired cell use the property Value to configure the value. So:

// configurando valor da primeira coluna, índice 0
dataGridView1.Rows[indice].Cells[0].Value = "meuValorAqui";
  • Thank you very much friend, I was doing the wrong syntax. Thanks

  • I’m glad it worked!

Browser other questions tagged

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