0

I have a combobox bound to a datatable. It has lot of records in it with long text.

I have set the display member path to show all the text but obviously that will take up lot of screen space. So, when the user clicks the dropdown I want to show the full display member path but upon selection I want to show maybe just first 10 characters? As shown this image.

Is there any way I can do this?

enter image description here

                            <ComboBox Name="Texas_AON" IsEditable="True"
                      Grid.Row="0" Grid.Column="1" Visibility="{Binding Source='TX_ASL', Converter={local:NistRuleToVisibilityConverter}, ConverterParameter='97'}"
                      ItemsSource="{Binding Data.Tables[TxOffenseCodes]}"
                      SelectedValuePath="Code"
                      DisplayMemberPath="Description"
                                  VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" 
                          VirtualizingStackPanel.IsContainerVirtualizable="True" VirtualizingStackPanel.IsVirtualizingWhenGrouping="True"
                      Style="{DynamicResource PerformanceComboBox}" Margin="2" FontSize="12"  >
                            <ComboBox.SelectedValue>
                                <Binding Path="NF.t2.Texas412.Offenses[0].AON" Mode="TwoWay" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" ValidatesOnExceptions="True" >
                                    <Binding.ValidationRules>
                                        <local:FieldValidator ValidatesOnTargetUpdated="True" FieldName="AON" FieldNum="97"/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </ComboBox.SelectedValue>
                            <ComboBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel />
                                </ItemsPanelTemplate>
                            </ComboBox.ItemsPanel>
                        </ComboBox>
user3598756
  • 28,893
  • 4
  • 18
  • 28
Jay
  • 89
  • 1
  • 12
  • 1
    you should use something like [this](http://stackoverflow.com/a/1598224/2470362) – Abin Nov 17 '16 at 20:05
  • This restricted me from typing more than 10 characters (MaxLength=10) but still showed the whole line after selection. – Jay Nov 18 '16 at 14:57
  • you need to set the `ComboBox` width to adjust it i believe. – Abin Nov 18 '16 at 14:59
  • If I set the combo box width, it does help but then displays the right most part of the string. For example if the string is "sample very long line to test" then it shows "to test" part in the combo box instead of "sample" – Jay Nov 18 '16 at 15:09
  • Ohh Normal combo box is not doing that. as i have tested it in my machine, This show the first letters of the selected item. – Abin Nov 18 '16 at 15:17
  • Tis is weird, I removed all styling and templates but my selection always shifts to the right part. Let me try to identify the problem causing this lol. Cruel life of developers, looks right but still doesn't work right. :( Thanks! – Jay Nov 18 '16 at 16:00
  • Okay here is the thing, if you make it IsEditable="True" it points to the right :( – Jay Nov 18 '16 at 16:10
  • Ok then you should find a way to take the cursor to the starting position. do you really need to edit ? – Abin Nov 18 '16 at 16:12
  • Its not extremely* important but helps the user type out a value rather than search for it. He can still type the value with it IsEditable="False" but it wont show what he is typing which can get confusing if he wants to backspace or made a error while typing. – Jay Nov 18 '16 at 16:24

0 Answers0