This is a migrated thread and some comments may be shown as answers.

GridViewComboBoxColumn Get Cell Selected Text

15 Answers 855 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 15 Feb 2012, 10:42 AM
Hi,

Is it possible to get the selected text value of a GridViewComboBoxColumn for a set cell in a row?

thanks

David

15 Answers, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 20 Feb 2012, 09:26 AM
Hi David,

Thank you for contacting us.

You are able to get the value of a RadComboBoxColumn's cell using the standard approach for accessing cells described in this article. In case I have misunderstood your question, please provide further details about your scenario.

Greetings,
Boryana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vijay
Top achievements
Rank 1
answered on 13 Dec 2013, 05:20 AM
Hi, sorry to all as I know this is an old post, but I've been looking for similar solutions for a few days (and have been to many that have been written here). 

I have a RadGridView with a GridViewComboBoxColumn "Operation". 

I have an object (objID, objCode,....) that I am using as the data source for this GridViewComboBoxColumn
The DisplayMember = "objCode" while the ValueMember = "ObjID"

I would like to find out how to retrieve the "objCode" value currently chosen in the GridViewComboBoxColumn. 

Thanks!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Dec 2013, 03:43 PM
Hello Vijay,

Thank you for contacting Telerik Support.

In order to get the display member value for GridComboBoxCellElement you may use the following approach:
public Form1()
{
    InitializeComponent();
 
    List<CustomObject> list = new List<CustomObject>();
    for (int i = 0; i < 10; i++)
    {
        list.Add(new CustomObject(i,"Code" + i));
    }
     
    GridViewComboBoxColumn comboCol = new GridViewComboBoxColumn("Combo column");
 
    comboCol.DataSource = list;
    comboCol.ValueMember = "ID";
    comboCol.DisplayMember = "Code";
    this.radGridView1.Columns.Add(comboCol);
 
    this.radGridView1.CellClick += radGridView1_CellClick;
}
 
private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
    GridComboBoxCellElement cell = sender as GridComboBoxCellElement;
    if (e.Column is GridViewComboBoxColumn && cell != null)
    {
        if (!string.IsNullOrEmpty(cell.Text))
        {
            //CustomObject.Code
            MessageBox.Show(cell.Text);
        }
    }
}
 
public class CustomObject
{
    public int ID { get; set; }
 
    public string Code { get; set; }
 
    public CustomObject(int iD, string code)
    {
        this.ID = iD;
        this.Code = code;
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Vijay
Top achievements
Rank 1
answered on 18 Dec 2013, 12:18 AM
Hi, that's quite informative.

I'm trying to get the GridComboBoxCellElement within CellValidating handler. Is this possible?
When I try to use the GridDataCellElement Text Property (from grid.CurrentCell) the value is empty string at this time.

I have tested the solution in Cellclick. 
I can see that I could probably set the cell text in either CellClick (if clicked) or possibly CellBeginEdit and save to use when required.
However, it would be ideal to retrieve the GridComboBoxCellElement in RowValidating/CellValidating, if possible.

Tips are appreciated!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Dec 2013, 07:28 AM
Hello Vijay,

Thank you for writing back.

You can obtain an empty value in the CellValidating event when you are in edit mode in the New row. However, you can access the string value via the active editor element. Otherwise, when the grid is not in edit mode you can get the string value from the current cell's text. Here is a sample code snippet:
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    RadGridView grid = sender as RadGridView;
    if (grid.EditorManager.ActiveEditor != null)//edit mode
    {
        RadDropDownListEditor editor = grid.EditorManager.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            RadDropDownListEditorElement element = editor.EditorElement as RadDropDownListEditorElement;
            MessageBox.Show(element.Text);
        }
    }
    else
    {
        MessageBox.Show(grid.CurrentCell.Text);
    }
}

Please do not hesitate to contact us if you have any additional questions.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 22 Jan 2015, 05:03 PM
Hi,
Is there anyway to retrieve the DisplayMember value of GridViewComboBoxColumn in the CellEndEdit ? Thanks.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jan 2015, 09:50 AM
Hello Tom,

Thank you for writing.

In the CellEndEdit event you can directly get the CurrentCell.Text property:
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    GridViewEditManager editManager = sender as GridViewEditManager;
    if (editManager !=null)
    {
        Console.WriteLine(editManager.GridViewElement.CurrentCell.Text);
    }
}

Note that the GridViewComboBoxColumn offers the GetLookupValue(object cellValue) method which returns the lookup value corresponding to the specified cell value.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tom
Top achievements
Rank 1
answered on 27 Jan 2015, 06:35 PM
It is working fine if I choose the DropDownStyle is DropDownList or I select the item in the list of the style DropDown. But when I type in the new value in the style DropDown, the editManager.GridViewElement.CurrentCell.Text return empty value.
Thanks.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Jan 2015, 10:53 AM
Hello Tom,

Thank you for writing back.

If you set the GridViewComboBoxColumn.AutoCompleteMode property to AutoCompleteMode.Append, when typing in the editable part of the RadDropDownListEditor, you will obtain appended the first suggestion. As a result, the selected value will be updated and when the CellEndEdit event is fired, you will see the editManager.GridViewElement.CurrentCell.Text. However, if you type a string that does not match any of the available items, the cell value will be set to null. This behavior is expected.

If you need to allow users to enter custom values, please have a look at our Allow end-users to add items to DropDownListEditor help article. 

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Scott
Top achievements
Rank 1
answered on 25 Nov 2017, 01:02 PM

Hi Dess-

Can I make a feature request?

Can we have a the GridView control updated to include something like this:  row.Cells["myColumn"].DisplayedValue along side row.Cells["myColumn"].Value.  They would both be the same except when you the column is a gridViewComboBoxColumn.

I regularly need to use data from a GridView that is bound to a datasource.  Adding a DisplayedValue string to the object list would make my job a whole lot easier.

Thank you for your consideration.

 

-Scott

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Nov 2017, 11:13 AM
Hello, Scott,

Thank you for writing.  

You can get the displayed text very easily by the GetLookupValue method of the GridViewComboBoxColumn. It is just necessary to pass the cell's value. Here is a sample code snippet:
private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
    GridViewComboBoxColumn comboColumn = e.Column as GridViewComboBoxColumn;
    if (comboColumn!=null)
    {
        object cellValue = e.Row.Cells[e.Column.Name].Value;
        Console.WriteLine(comboColumn.GetLookupValue(cellValue));
    }
}

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Scott
Top achievements
Rank 1
answered on 27 Nov 2017, 10:05 PM
I completely missed that.  Thank you, Dess!
0
Jeff
Top achievements
Rank 1
answered on 01 Sep 2018, 10:58 AM

Hi all team,
I curently have a radGridview populate by a datatable.
Once populated, I add a  GridViewComboBoxColumn also populated by an other DataTable :

GridViewComboBoxColumn relaying_stuff = new GridViewComboBoxColumn();
relaying_stuff.Name = "Relaying Stuff";
relaying_stuff.HeaderText = "Relaying Stuff";
relaying_stuff.DataSource = stuffSource;
relaying_stuff.ValueMember = "id_stuff";
relaying_stuff.DisplayMember = "name";
this.radGridView1.Columns.Add(relaying_stuff)

 

Only this ComboBoxColumn can be edited in the gridview.

What I do not succeed in performing is on "ComboBoxColumn change value of the dropdown list"  event, to get back the ValueMember "id_stuff" selected.

I have been trying with GetLookupValue function without any success. 

A piece of help would be highly appreciated..

Thanks in advance.

Jeff

0
Jeff
Top achievements
Rank 1
answered on 01 Sep 2018, 11:41 AM

I found the solution, that was so easy :

On ValueChanged event 

radGridView1.ActiveEditor.Value

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Sep 2018, 08:02 AM
Hello, Jeff,         

I am glad that you have found a suitable solution for your case. Please have in mind that the ActiveEditor.Value property will give you the selected value while the editor is active and the value is still not committed to the cell. Once the editor is closed and the value is stored in the cell, you can use the directly the cell's Value for the ValueMember and the previously suggested GridViewComboBoxColumn.GetLookupValue method for the DisplayMember.

If you have any additional questions, please let me know.  
 
Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
David
Top achievements
Rank 2
Answers by
Boryana
Telerik team
Vijay
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Tom
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Share this question
or