DataFormDataField does not have TextChanged event

4 posts, 0 answers
  1. Gavin
    Gavin avatar
    3 posts
    Member since:
    Oct 2016

    Posted 08 Nov Link to this post

    I have a RadDataForm with several DataFormDataFields and also some combo boxes.

    I need to attach some event handlers to the fields that are triggered whenever the user starts to edit the text contents in a field. I am using a data template to define the fields included in the form. I would like to have, in my data template, something like this, for example:

                        <telerik:DataFormDataField Label="Client's Name"
                                                   Grid.Row="16"
                                                   Width="500" HorizontalAlignment="Left" TextChanged="DataFormDataField_TextChanged"
                                                   DataMemberBinding="{Binding PaymentRequest.ClientName, Mode=TwoWay}" />

     

    and then in the code behind:

            private void DataFormDataField_TextChanged(object sender, System.Windows.Input.TextCompositionEventArgs e)
            {

                etc....
            }

     

    Unfortunately, the DataFormDataField does not provide a TextChanged event. I have tried instead using the TextInput (or TextInputStart event). This fires fine when the user types additional text into the field, but the event does not get fired when, for example, the user presses the backspace delete key. I need an event that will fire whenever the pre-filled text starts to get changed. Any ideas?

     

  2. Martin Vatev
    Admin
    Martin Vatev avatar
    90 posts

    Posted 11 Nov Link to this post

    Hi Gavin,

    For your convenience, I prepared an example to demonstrate how to achieve the desired behavior. Please take a look at the implementation and consider how this approach fits your scenario.

    I hope that this helps. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Martin Vatev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft banner
  4. Gavin
    Gavin avatar
    3 posts
    Member since:
    Oct 2016

    Posted 11 Nov in reply to Martin Vatev Link to this post

    Dear Martin,

    Thank you for this.

    I may be able to use this idea, but does this only work for Autogenerating fields?

    For example if in the XAML, instead of having AutoGenerateFields="True", you used a data template with the form, where you specified that only the fields FirstName, LastName and Occupation should be included in the form, where would you hook in the bit of code that starts with this.Dispatcher.BeginInvoke.... (etc.), as you wouldn't have the event handler DataForm1_AutoGeneratingField()?

     

    Regards,

     

    Gavin

  5. Martin Vatev
    Admin
    Martin Vatev avatar
    90 posts

    Posted 15 Nov Link to this post

    Hello Gavin,

    I apologize for the misunderstanding. To achieve the desired behavior you can add a handler to TextBox.TextChangedEvent. Please take a look at code snippet below for reference:

    public MainWindow()
     {
         InitializeComponent();
         this.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(OnTextChanged), true);
     }
     
     private void OnTextChanged(object sender, TextChangedEventArgs e)
     {
     
     }

    I hope this helps. If further assistance is needed, please feel free to contact us.

    Regards,
    Martin Vatev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top