Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following routine :

VB
Private Sub FormChanged(ByVal sender As Object, ByVal e As EventArgs) Handles _
    cbo_Contact.TextChanged, _
    cbo_Currency.TextChanged, _
    cbo_Delivery_Address.TextChanged, _
    cbo_Delivery_From.TextChanged, _
    cbo_Delivery_To.TextChanged, _
    cbo_General.TextChanged, _
    cbo_Payment_Terms.TextChanged, _
    cbo_Project_Number.TextChanged, _
    cbo_Supplier.TextChanged, _
    cbo_Type.TextChanged, _
    dtp_Delivery_Date_From.ValueChanged, _
    dtp_Delivery_Date_To.ValueChanged, _
    mxt_Settlement_Discount.TextChanged, _
    cbo_Description.TextChanged, _
    mxt_Qty.TextChanged, _
    cbo_Unit.TextChanged, _
    txt_Price.TextChanged, _
    txt_Discount.TextChanged, _
    cbo_Incoterm.TextChanged, _
    cbo_Inco_Named_Place.TextChanged, _
    cbo_Inco_Place.TextChanged, _
    chk_No_Vat.CheckedChanged, _
    rxt_Notes.TextChanged

    theFormChanged = True

End Sub


Obviously if any of the list comboboxes, textboxes etc changes then I know that something on the form has changed and a Save should occur.

Is there any way, within the above routine, that I can identify which one changed?

Something like :

if cbo_Supplier.TextChanged = True then DoSomething ???
Posted

Try this:
VB
If TypeOf sender Is ComboBox Then
          Dim MyCombo As ComboBox = CType(sender, ComboBox)
          MsgBox(MyCombo.Name)
      End If
 
Share this answer
 
v2
Comments
Darrell de Wet 21-Feb-13 6:24am    
Works like a dream - thank you.
Easy - the event handler provides it via the sender parameter.
 
Share this answer
 
Comments
Darrell de Wet 21-Feb-13 5:53am    
Ahh shoot, Ive tried everyting except that.
Thanks for your quick response and sorry if I wasted your time but thats how beginners learn I guess.

As a quick test I included a line :
msgbox(sender.ToString)
to see which sender and i got the result :
System.Windows.Forms.ComboBox.Items.Count:2

Your solution is a step in the right direction but with 15 odd Comboxes it still does not tell me which one the sender is.

Can you assists a little further?

I appreciate the help.
OriginalGriff 21-Feb-13 6:34am    
Everyone starts somewhere! :laugh:
It's pretty simple: sender arrives as a object, and unless the final class in the inheritance chain implements ToString you will get the default implementation - which returns the class name information rather than the content. (This is normal for controls where the actual human readable data is not obvious to the control)
As Raimis9 suggest, convert it to a combobox and either use it directly, or get the Name property from that.
Darrell de Wet 21-Feb-13 6:37am    
Thanks again. I used Raimis9 advise and it worked beautifully.
You have both taught me something - appreciate it !!
OriginalGriff 21-Feb-13 7:05am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900