valor de columna en datagridview

i use these following codes to get cell's value in datagridview. these codes show me each cell has been clicked. i want to use some codes just show me special column for example column with index 1 but these codes show me each which has been clicked. Imagine i just want to show column 1 with it's clicked cell. please help me to solve this

string str = dataGridView1.CurrentCell.Value.ToString();

Gracias por adelantado

preguntado el 03 de mayo de 12 a las 19:05

1 Respuestas

So you're trying to get the data from the second column for every row?

int index = 1;
foreach (DataGridViewRow row in dataGridView1.Rows)
    DataGridViewCell cell = row.Cells[index];
    // Do something.

Edit: Per your comment, you're trying to get the value of the second column when any cell in the row is clicked. Try this:

string str = dataGridView1[1, e.RowIndex].Value.ToString();

contestado el 03 de mayo de 12 a las 20:05

i got a problem with this code. when i click on each cell it will show me all rows with column 1 index - aliprogramador

btw it starts from the first row. not a specific row - aliprogramador

Edited - Was hard to understand your original question. - Zimdanen

column index 1 with that clicked cell's row - aliprogramador

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.