2

Isn't there a way to tell what control fired a routed event? I have a SelectionChangedEvent for use by a combobox on a radgridview. I want the coding in that event to handle only that combobox and no others. I tried using e.OriginalSource.Name, ToString, sender.ToString, sender.Name but all return "". So there's no way to tell what combobox is being processed by the event.

Code to create event:

Me.AddHandler(RadComboBox.SelectionChangedEvent, New System.Windows.Controls.SelectionChangedEventHandler(AddressOf FinishedEndsChanged))

Code inside event:

    Private Sub FinishedEndsChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        Try
            If dgChosenItems.SelectedItems.Count > 0 Then
                Dim comboBox As RadComboBox = CType(e.OriginalSource, RadComboBox)

                If comboBox.SelectedValue IsNot Nothing Then
                    Dim endChosen As String = CStr(comboBox.SelectedValue)

Thanks.

EManning
  • 81
  • 1
  • 9
  • The `sender` parameter will be the combo box that fired the event. So you can say `If sender Is RadComboBox Then...`. I assume you're doing this because you're using the same event hander for a bunch of combo boxes but you want a special case for that one. A cleaner solution would be to give it an event handler that is only used for that combo box. – dwilliss Jan 04 '18 at 22:45

2 Answers2

0

Give your ComboBox a name so you can address it in sourcecode-behind by this unique name. Check

If e.OriginalSource == _youridhere_ Then // If sender == ... should work as well 
    // do what you must 

Not very good style and probably only feasable for one to a few boxes...

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • It has a name: "cboEnds". But plugging that name in where you suggest gives an "expression expected" error. – EManning Jan 04 '18 at 21:20
  • @EManning I am more familiar with c# - how do you create an expression that asserts if one object is the same as another object in VB? I.e. if `sender` is / == / Equals `cboEnds` – Patrick Artner Jan 04 '18 at 21:32
  • I believe I found the answer here: https://www.telerik.com/forums/selection-changed-event-for-gridviewcombobox-column. I used the SelectedValuePath option. So far, so good! Thanks for taking the time to reply. – EManning Jan 04 '18 at 21:42
  • 1
    @EManning consider self-answering and selecting that answer in 2 days. wont give you rep, but might help some later visiter of your problem – Patrick Artner Jan 04 '18 at 21:55
0

I believe I found the answer here: [https://www.telerik.com/forums/selection-changed-event-for-gridviewcombobox-column]

I chose to use SelectedValudPath.

Thanks, Patrick, for taking the time to reply.

EManning
  • 81
  • 1
  • 9