Ticket Q582911
Visible to All Users

Suggested way to handle ProcessNewValue from ComboBoxEditSettings MVVM way

created 11 years ago

I have reviewed a couple of options from your documentation to handle ProcessNewValue event but hasn't fully got what is the recommended way to do the below tasks with MVVM with the current version of DXGrid
- process the new value only when the user hits enter (now in the below code it will processed on every letter insert)
- on value processing handler, add the new object to itemssource where the newly entered String will be set to object's DisplayMember property
- if AddNewButtonPlacement is specified, open a dialog to enter values for the new object
Current code (which requires code-behind):

C#
<dxg:GridColumn FieldName="parentID"> <dxg:GridColumn.EditSettings> <dxe:ComboBoxEditSettings AutoComplete="True" ImmediatePopup="True" IncrementalFiltering="True" IsTextEditable="True" ItemsSource="{Binding MyParent.Childrents, Mode=TwoWay}" ValueMember="Id" DisplayMember="Name" AddNewButtonPlacement="Popup" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn>
C#
<dxg:TableView ShownEditor="view_ShownEditor">
Visual Basic
Private Sub view_ShownEditor(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.EditorEventArgs) If e.Column.FieldName = "parentID" Then Dim comboBoxEdit As ComboBoxEdit = DirectCast(e.Editor, ComboBoxEdit) If DirectCast(comboBoxEdit.Tag, String) = "ProcessNewValueHandlerAssigned" Then Return End If AddHandler comboBoxEdit.ProcessNewValue, AddressOf comboBoxEdit_ProcessNewValue comboBoxEdit.Tag = "ProcessNewValueHandlerAssigned" End If End Sub Private Sub comboBoxEdit_ProcessNewValue(ByVal sender As DependencyObject, ByVal e As ProcessNewValueEventArgs) 'process value here... End Sub

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
To process new values when Enter is pressed, set ValidateOnTextInput to 'False' and 'ValidateOnEnterKeyPressed' to true. To get rid of extra code-behind, you can create an attached property and implement all logic in it. I have attached a sample project to illustrate this approach.
As for opening a dialog when the button is clicked, I suggest that you add a button to the ComboBoxEditSettings.Buttons collection and show the dialog in the Click event handler.
Thanks,
Alexander

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.