Get value from a cell in DataGridView into a TextBox when using BindingNavigator
I want to populate 开发者_C百科some text boxes while clicking the next row on the BindingNavigator
.
I can use for the first text box:
textBox1.Text = dataGridView1.CurrentCell.Value.ToString();
but I also want to get the info from cells 2 and 3 into textBox2
and textBox3
. How can I access these based on what row is currently selected?
Try This
textBox1.Text = dataGridView1.CurrentRow.Cells["Column name"].Value.ToString();
OR
textBox1.Text = dataGridView1.CurrentRow.Cells[Column index].Value.ToString();
To get the current row use the dataGridView1.CurrentCell.RowIndex
property value.
精彩评论