How to obtain data from a selected cell in datagridview c #?

0

I have a Datagridview named dgv , in the doubleclick event of this * dgv * I need to get the value that cell where I made doubleclick , the name of the column where that cell is and the value of the first row where that cell is. I enclose an image to explain myself better

I need to get the value of the cell selected in this case would be the word "RESERVED", I also need to get the name of that column in this case "Wed. 13 Sept." and get the value of the first column of this row for this case would be "11:30".

I hope you can help me. Thanks

    
asked by JDiego9708 23.09.2017 в 02:13
source

1 answer

0

If you analyze the documentation of the event

DataGridView.CellDoubleClick

You will see two arguments e.ColumnIndex and e.RowIndex using the following way

public void DataGridView1_private void DataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) {

    //obtienes el valor reservado
    string valorCelda = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

    //nombre columna
    string nombrecolumna = DataGridView1.Columns[e.ColumnIndex].HeaderText;

    //obtienes el valor de la primer columna
    string valorPrimerCelda = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();

}

to get the data you need

    
answered by 23.09.2017 / 15:59
source