access the selected value of a GridViewComboBoxColumn?

9 posts, 0 answers
  1. Scott
    Scott avatar
    1 posts
    Member since:
    Sep 2007

    Posted 26 Jan 2009 Link to this post

    How do I access the selected value of a GridViewComboBoxColumn when the selected value changes? What gridview event should I be handling? Thanks!
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Jan 2009 Link to this post

    Hi Scott,

    Thank you for the question.

    There is a ValueChanged event that you can subscribe to. In your case the sender parameter will be a GridViewComboBoxCellElement which has a Value property. Use this property to take action appropriate to your situation.

    I hope this is what you are looking for. Please write back if you have more questions.

    All the best,
    Victor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 29 Jan 2010 Link to this post

    Scott,
    I'm having trouble finding GridViewComboBoxCellElement.  How do I get this property value?

    Thank You
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 01 Feb 2010 Link to this post

    Hello jerry,

    Thank you for your question. GridViewComboBoxCellElement is a type, not a property. You have to subscribe to RadGridView ValueChanged event and safely cast the sender reference to a GridViewComboBoxCellElement. If the cast is successful you can get the Value property of the casted object. Please write again if you have other questions.

    Sincerely yours,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 01 Feb 2010 Link to this post

    Victor,
    When I try and cast sender I don't get an option for GridViewComboBoxCellElement. 

    I'm trying to do
    GridViewComboBoxCellElement cmbCE = sender as GridViewComboBoxCellElement;

    But it tells me that it doesn't exist.  Am I missing something?


    Thank You
  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 01 Feb 2010 Link to this post

    Hi jerry,

    Please excuse my colleague Victor for the naming error. Actually, the correct type of the combobox cell is:
    GridComboBoxCellElement.

    If you have additional questions, feel free to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Gone2TheDogs
    Gone2TheDogs avatar
    22 posts
    Member since:
    May 2016

    Posted 01 Nov Link to this post

    I know this thread is a bit long in the tooth, but it was what I found for what I needed. I'm using VB.NET and here is what I have. It is failing with an InvalidCastException on Line 4 (DirectCast). What should I be doing to get the selected value? 

    1.Private Sub dgvVenWarehouses_ValueChanged(sender As Object, e As System.EventArgs) Handles dgvVenWarehouses.ValueChanged
    2. 
    3.Dim cellElement As GridComboBoxCellElement
    4. cellElement = DirectCast(sender, GridComboBoxCellElement)
    5. value = cellElement.Value
  9. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 02 Nov Link to this post

    Hello Bob,

    Thank you for writing.  

    The RadGridView.ValueChanged event is fired when the editor's value is updated. The sender in this event is the editor, not the cell. However, note that the value is not committed to the cell yet until the user presses Enter or navigates to another cell. You can find below a sample code snippet demonstrating how to get the newly selected value and the corresponding displayed value:
    Sub New()
        InitializeComponent()
        Dim categoriesColumn As GridViewComboBoxColumn = New GridViewComboBoxColumn("Combo col")
        categoriesColumn.DataSource = Me.CategoriesBindingSource
        categoriesColumn.ValueMember = "CategoryID"
        categoriesColumn.DisplayMember = "CategoryName"
        categoriesColumn.FieldName = "CategoryID"
        Me.RadGridView1.Columns.Add(categoriesColumn)
        Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
     
        AddHandler Me.RadGridView1.ValueChanged, AddressOf ValueChanged
    End Sub
     
    Private Sub ValueChanged(sender As Object, e As EventArgs)
        Dim editor As RadDropDownListEditor = TryCast(sender, RadDropDownListEditor)
        If editor IsNot Nothing Then
            Dim comboCol As GridViewComboBoxColumn = TryCast(Me.RadGridView1.CurrentColumn, GridViewComboBoxColumn)
            Console.WriteLine("New cell's value: " & editor.Value)
            Console.WriteLine("New cell's displayed value: " & comboCol.GetLookupValue(editor.Value))
        End If
    End Sub

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

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  10. Gone2TheDogs
    Gone2TheDogs avatar
    22 posts
    Member since:
    May 2016

    Posted 02 Nov in reply to Dess Link to this post

    great explanation. Thanks, Dess.
Back to Top
UI for WinForms is Visual Studio 2017 Ready