GridViewComboBoxColumn Get Cell Selected Text

10 posts, 0 answers
  1. David
    David  avatar
    66 posts
    Member since:
    Aug 2010

    Posted 15 Feb 2012 Link to this post

    Hi,

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

    thanks

    David
  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 20 Feb 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Vijay
    Vijay avatar
    7 posts
    Member since:
    May 2013

    Posted 12 Dec 2013 Link to this post

    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!
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 17 Dec 2013 Link to this post

    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 >>
  6. Vijay
    Vijay avatar
    7 posts
    Member since:
    May 2013

    Posted 17 Dec 2013 Link to this post

    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!
  7. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 21 Dec 2013 Link to this post

    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 >>
  8. Tom
    Tom avatar
    9 posts
    Member since:
    Jan 2013

    Posted 22 Jan 2015 in reply to Dess Link to this post

    Hi,
    Is there anyway to retrieve the DisplayMember value of GridViewComboBoxColumn in the CellEndEdit ? Thanks.
  9. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 27 Jan 2015 Link to this post

    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.

     
  10. Tom
    Tom avatar
    9 posts
    Member since:
    Jan 2013

    Posted 27 Jan 2015 in reply to Dess Link to this post

    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.
  11. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Jan 2015 Link to this post

    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.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready