aliprogrammer
aliprogrammer

Reputation: 197

column value in 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();

Thanks in advance

Upvotes: 0

Views: 90

Answers (1)

zimdanen
zimdanen

Reputation: 5626

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();

Upvotes: 1

Related Questions