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

DataFormDataField does not have TextChanged event

3 Answers 95 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 08 Nov 2016, 12:45 PM

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?

 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 11 Nov 2016, 07:49 AM
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.
0
Gavin
Top achievements
Rank 1
answered on 11 Nov 2016, 09:21 AM

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

0
Martin
Telerik team
answered on 15 Nov 2016, 12:53 PM
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.
Tags
DataForm
Asked by
Gavin
Top achievements
Rank 1
Answers by
Martin
Telerik team
Gavin
Top achievements
Rank 1
Share this question
or