Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Consider the following picture

enter image description here

I get the selected row values in the three textboxes shown in the figure when i click a cell using following code.

void dataGridView1_CellClick_1(object sender, DataGridViewCellEventArgs e) {
    TBGRNo.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
    TBSName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
    TBFName.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
}

My Question is: how will I do the same thing in DevExpress XtraGrid control??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
639 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is the way that I've followed,

int[] selRows = ((GridView)gridControl1.MainView).GetSelectedRows();
DataRowView selRow = (DataRowView)(((GridView)gridControl1.MainView).GetRow(selRows[0]));
txtName.Text = selRow["name"].ToString();

Also you can iterate through selected rows using the selRows array. Here the code describes how to get data only from first selected row. You can insert these code lines to click event of the grid.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...