我正在使用Telerik的RadGridView来显示一些数据。此gridview中的一个列是一个组合框,其填充方式如下:
DataTable dtContractorName = A133DB.GetContractorsForCombo(true);
GridViewComboBoxColumn contractorNameColumn = new GridViewComboBoxColumn();
contractorNameColumn.UniqueName = "ContractorID";
contractorNameColumn.HeaderText = "Contractor";
contractorNameColumn.DataSource = dtContractorName;
contractorNameColumn.ValueMember = "ContractorID";
contractorNameColumn.DisplayMember = "ContractorName";
contractorNameColumn.FieldName = "ContractorID";
radGvReviews.Columns.Add(contractorNameColumn);
这适用于在gridview中正确显示数据,但我想在双击单元格时在表单的单独部分显示当前行的displaymember。
示例:
private void radGvReviews_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
MessageBox.Show(e.Row.Cells["ContractorID"].Value.ToString());
}
不幸的是,这只会显示列的ValueMember(即1,而不是Fred; 2,而不是Bob),并且控件不包含“DisplayMember”或“Text”属性的定义(我在哪里)期望找到实际显示在屏幕上的值。)
关于这个的任何想法?
答案 0 :(得分:2)
这应该有效:
void radGridView1_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
GridViewComboBoxColumn comboCol = e.Column as GridViewComboBoxColumn;
if (comboCol != null)
{
DataTable source = comboCol.DataSource as DataTable;
foreach (DataRow row in source.Rows)
{
if (row["ContractorID"].Equals(e.Value))
{
MessageBox.Show(row["ContractorName"].ToString());
return;
}
}
}
}
答案 1 :(得分:1)
您需要获取该单元格的GridViewComboBoxColumn
。然后访问DisplayMember属性
编辑:更新了示例
private void radGvReviews_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
GridViewComboBoxColumn combo = radGvReviews.Columns[e.ColumnIndex] as GridViewComboBoxColumn;
if (combo != null)
{
MessageBox.Show(combo.DisplayMember);
}
}
答案 2 :(得分:1)
看看the documentation for CellDoubleClick。它似乎告诉我你可以从e.Value