Comobo Box editable

Grids for WPF Forum

Posted 14 years ago by Eli Obadia
Version: 10.2.0531
Avatar
One of the properties I have is a text that could have some predefined values, I'd like for that to have an editable combobox, so the end user could type a new value or just select the predefined ones. But the predefined one are dinamically defined (basically they are the previous values already introduced for that same property), what's the best way do implement? is there any predefined editor for this case?

Thanks!
Eli

Comments (4)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Eli,

We don't have a built-in editor for this case, and is something you'd have to build.

You can take our ComboBox property editor DataTemplate and use that as a basis. You would need to bind the to Text property and update the Items when the change is "committed", which is usually when the focus is lost.


Actipro Software Support

Posted 14 years ago by Eli Obadia
Avatar
Thank you!,

I defines in App.xaml
        <DataTemplate  x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type sample:Combo_Editor}, ResourceId=Combo_EditorRsc}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox Grid.Column="0" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Center"
              BorderThickness="0"
              Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
              IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}}" />
                <ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Name="Combo_Editor" VerticalAlignment="Top" SelectionChanged="Combo_Editor_SelectionChanged" Width="120">
                    <ComboBoxItem Content="First" IsSelected="True" />
                    <ComboBoxItem Content="SEcond" />
                </ComboBox>
            </Grid>
        </DataTemplate>
The 2 questions are:

1) where do I define the code to handle when the selection is changed (Combo_Editor_SelectionChanged) and which paarameters will have my code (I couldn't define a command because is a combo box noty a button)??

2) How can I access from the the get in the Object definition taht is being used by the propertyGrid the selected value on the combo?

Thanks!,
Eli
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Eli,

1. You may be able to put the handler in the code-behind for your application. I'm not sure what you are asking in the rest of the question.

If you can't add the handler to the application code-behind, you'd probably have to build a custom attached behavior (which would add a handler for SelectionChanged).

2. I believe you want the IPropertyDataAccessor.Target, which holds a reference to the object that contains the property wrapped by the IPropertyDataAccessor.


Actipro Software Support

Posted 14 years ago by Eli Obadia
Avatar
Thanks!
The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.