Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
Button Event
posted

 

 

 

I have a button column with a click command that goes to this method.  How do I find out which row/record it came from?

Private Sub OnContactInfoClick(ByVal sender As Object, ByVal e As Windows.RoutedEventArgs)

 

 

End Sub

  • 2677
    Suggested Answer
    posted

    Hello,

    Sorry for not getting to this post in a timely manner.  I hope this can still help.  In situations like this where you only have the context of the button, you will have to crawl up the VisualTree to find the CellValuePresenter.  From there, you can get the Record. Here is a code snippet.

    DependencyObject dobj = e.OriginalSource as DependencyObject;
                while (dobj != null && dobj.GetType() != typeof(CellValuePresenter))
                {
                    dobj = VisualTreeHelper.GetParent(dobj);

                }
                if (dobj != null)
                {
                    CellValuePresenter cvp = dobj as CellValuePresenter;
                    DataRecord dr = cvp.Record;
                }

    I quickly put this together.  You can also write recursive functions to handle this.  I hope this helps.