如何获取DevExpress XtraGrid的选定行值? [英] How to get the selected row values of DevExpress XtraGrid?
问题描述
请考虑以下图片
当我点击使用以下代码的单元格时,我会在图中显示的三个文本框中获取选定的行值。
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();
}
我的问题是:如何在DevExpress XtraGrid控件中做同样的事情? ?
My Question is: how will I do the same thing in DevExpress XtraGrid control??
推荐答案
您可以通过多种方式执行此操作。您可以使用数据绑定(典型的初始化为InitializeComponent();)
You can do this in a number of ways. You can use databinding (typical initialized after InitializeComponent();)
textBox1.DataBindings.Add(new Binding("Text", yourBindingSource,
"TableName.ColumnName", true, DataSourceUpdateMode.OnPropertyChanged));
或使用DataLayoutControl(如果要使用文本框进行编辑,我真的建议花一些时间以了解如何使用此组件。
or use a DataLayoutControl (if you are going to use textbox for editing, I really recommend spending some time to learn how to use this component.
或通过从以下方法之一分配在FocusedRowChanged中:
or in FocusedRowChanged by assigning from one of these methods:
textBox1.Text = gridView1.GetDataRow(e.FocusedRowHandle)["Name"].ToString();
textBox1.Text = gridView1.GetFocusedDataRow()["Name"].ToString();
textBox1.Text = (gridView1.GetFocusedRow() as DataRowView).Row["Name"].ToString();
textBox1.Text = gridView1.GetFocusedRowCellValue("Name").ToString();
这篇关于如何获取DevExpress XtraGrid的选定行值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!