Click here to Skip to main content
15,904,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

hi there. i have following XAML code:

XML
<ComboBox x:Name="MainComboBox" Height="35" Width="250" removed="WhiteSmoke" BorderBrush="Gray"
                  IsEditable="True" TextSearch.TextPath="Name" TextBoxBase.TextChanged="MainComboBox_TextChanged">
            <ComboBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
            </ComboBox.Resources>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TreeView BorderBrush="Transparent" BorderThickness="0" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}, Mode=FindAncestor}, Path=ItemsSource}">
                        <TreeView.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type data:SubscriberGroupModel}">
                                <CheckBox Content="{Binding Name}" Height="25" Width="80" />
                            </HierarchicalDataTemplate>
                        </TreeView.ItemTemplate>
                    </TreeView>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>


and my code behind:
C#
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    List<SubscriberGroupModel> list = SubscriberGroupDB.GetCustomSubscriberGroup();
    MainComboBox.ItemsSource = list;
}

this control doesn't work properly because it produces itms more than once.
my query s correct.
please help me.
thanks alot
Posted
Updated 26-Jan-14 20:57pm
v2
Comments
AnthonyMG 27-Jan-14 4:14am    
could you please let me know what your trying to achieve with this combobox,
can you specify your need of combobox using ItemTemplate ?
aliwpf 27-Jan-14 4:27am    
No

1 solution

Hey Ali, Please follow these steps. I check this on my side and it works..

1) Add Childern as one more property in SubscriberGroupModel class. It means -

C#
List<Subscribergroupmodel> childern;
public List<Subscribergroupmodel> Childern
{
  get { return childern; }
  set
  {
      childern = value;
      NotifyPropertyChanged("Childern");
   }
}


2)After that change the Loaded method - (Window_Loaded)

C#
private void Window_Loaded(object sender, RoutedEventArgs e)
 {
    List<Subscribergroupmodel> list = SubscriberGroupDB.GetCustomSubscriberGroup();
    SubscriberGroupModel sgmobj = new SubscriberGroupModel();
    sgmobj.Childern = list;

    List<Subscribergroupmodel> obj = new List<Subscribergroupmodel>();
    obj.Add(sgmobj);

    MainComboBox.ItemsSource = obj;

  }


3) And Lastly change in your XAML -

HTML
<ComboBox x:Name="MainComboBox" TextBoxBase.TextChanged="MainComboBox_TextChanged">           
     <ComboBox.ItemTemplate>
         <DataTemplate>
             <TreeView BorderBrush="Transparent" BorderThickness="0" ItemsSource="{Binding Childern}">
                  <TreeView.ItemTemplate>
                       <HierarchicalDataTemplate >
                            <CheckBox Content="{Binding Name}" Height="25" Width="80" />
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate>
             </TreeView>
          </DataTemplate>
      </ComboBox.ItemTemplate>
  </ComboBox>



I hope this will solve your problem...
 
Share this answer
 
v4

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