views:

1421

answers:

2

Hi,

I am using Telerik's RadGridView to display some data. One of the columns in this gridview is a combobox, which is populated like so:

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

This works just fine for displaying the data properly in the gridview, but I would like to also show the displaymember of the current row on a separate part of my form when the cell is double-clicked.

Example:

private void radGvReviews_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
    MessageBox.Show(e.Row.Cells["ContractorID"].Value.ToString());
}

Unfortunately, this will only display the ValueMember for the column (i.e. 1, instead of Fred; 2, instead of Bob), and the control does not contain a definition for the "DisplayMember" or "Text" properties (where I would expect to find the value that is actually being displayed on screen).

Any ideas on this one?

A: 

You need to get the GridViewComboBoxColumn for that cell. Then access the DisplayMember property

Edit: Updated Sample

private void radGvReviews_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
     GridViewComboBoxColumn combo = radGvReviews.Columns[e.ColumnIndex] as GridViewComboBoxColumn;
     if (combo != null)
     {
              MessageBox.Show(combo.DisplayMember);
     }
}
Michael G
Michael, I failed to mention that I have tried your code sample previously. When attempted, I receive a "Cannot convert type 'Telerik.WinControls.UI.GridViewCellInfo' to 'Telerik.WinControls.UI.GridViewComboBoxColumn' via a reference conversion, etc., etc." Any other suggestions?
Robert
A: 

Look at the documentation for CellDoubleClick. It seems to tell me that you can get the text you want from e.Value

LaustN