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

access the selected value of a GridViewComboBoxColumn?

8 Answers 427 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 26 Jan 2009, 06:14 AM
How do I access the selected value of a GridViewComboBoxColumn when the selected value changes? What gridview event should I be handling? Thanks!

8 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 29 Jan 2009, 07:59 AM
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.
0
jerry
Top achievements
Rank 1
answered on 29 Jan 2010, 07:49 PM
Scott,
I'm having trouble finding GridViewComboBoxCellElement.  How do I get this property value?

Thank You
0
Victor
Telerik team
answered on 01 Feb 2010, 10:13 AM
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.
0
jerry
Top achievements
Rank 1
answered on 01 Feb 2010, 02:43 PM
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
0
Nikolay
Telerik team
answered on 01 Feb 2010, 02:56 PM
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.
0
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
answered on 01 Nov 2016, 06:28 PM

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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Nov 2016, 01:09 PM
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.
0
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
answered on 02 Nov 2016, 01:12 PM
great explanation. Thanks, Dess.
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Victor
Telerik team
jerry
Top achievements
Rank 1
Nikolay
Telerik team
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or