Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This method creates an AutoCompleteBox object

C#
private AutoCompleteBox criaAutoCompletBox()
        {
            AutoCompleteBox acBox = new AutoCompleteBox();
            acBox.FilterMode = AutoCompleteFilterMode.ContainsOrdinal;
            acBox.IsTextCompletionEnabled = true;
            acBox.ValueMemberPath = "designacao";
            acBox.SetValue(Grid.MinWidthProperty, 100.0);
            acBox.SetValue(Grid.HeightProperty, 20.0);
            acBox.SetValue(Grid.MarginProperty, new Thickness(5, 0, 0, 0));

            return acBox;
        }



After created the AutoCompleteBox, this code snippet make the set of ItemSource,but does not show the desired attribute, only shows a list of the type of instantiated object

C#
void rptacb_geraTabelaDadosCompleted(object sender, ReportWriterService.geraTabelaDadosCompletedEventArgs e)
        {
            try
            {
                for (int i = 0; i < relatorio.FC_RELATORIO_PARAMETROS.Count; i++)
                {
                    string tipo = relatorio.FC_RELATORIO_PARAMETROS.ElementAt(i).FCRP_TIPO;
                        AutoCompleteBox acb = ((System.Windows.Controls.AutoCompleteBox)(this.FindName(e.Result.campo)));
                        acb.ItemsSource = e.Result.tabela;
                }
            }
            catch (Exception ex)
            {
                new IMessage(ex).Show();
                Busy.appIsBusy(false);
            }
        }


I read on some forums, but found only one code in Xaml which is configured using the ItemTamplete, DataTemplate and TextBlock, but I do not how to do in C #.

XML
<sdk:AutoCompleteBox Grid.Column="1"  Margin="2,0" Height="23" FilterMode="Contains" Padding="0"  ItemsSource="{Binding}" ValueMemberPath="designacao"  Width="Auto" Name="acbPesqProduto"  HorizontalAlignment="Stretch">
                       <sdk:AutoCompleteBox.ItemTemplate>
                           <DataTemplate>
                               <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
                                   <TextBlock Text="{Binding Path=designacao}" Margin="0,0,0,10"/>
                               </StackPanel>
                           </DataTemplate>
                       </sdk:AutoCompleteBox.ItemTemplate>
                   </sdk:AutoCompleteBox>

I would like to have a similar code in C# or one that helps me to show the attribute "designacao" in my AutoComleteBox list,
Posted
Updated 7-Apr-15 11:20am
v2
Comments
Sinisa Hajnal 8-Apr-15 2:20am    
Is there a reason why you don't want to use XAML?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900