Get display value from combobox in radgridview

I am using Telerik RadGridView to display some data. One of the columns in this gridview is a combobox that populates like this:

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 is great for displaying data correctly in a gridview, but I would also like to show the displaymember of the current row in 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 (for example, 1 instead of Fred; 2 instead of Bob), and the control does not contain a definition of the "DisplayMember" or "Text" properties (where I will expect to find the value that actually appears on the screen) .

Any ideas on this?

+3
3

:

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;
            }
        }
    }
}
+2

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);
     }
}
+1

See the documentation for CellDoubleClick . It seems to me that you can get the text you want frome.Value

+1
source

Source: https://habr.com/ru/post/1721199/


All Articles