Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Binding DataTable to ComboBox Items with Itemtemplate

$
0
0

Hi and thanks,

I got a data template for my comboBox area, it will be used to create a list of MyItem on runtime.

However, the comboBox item value List is get from SQL database, so I got a DataTable myComboBoxList (Data e.g. Mary, Peter,...).

How to bind to the datatable to comboBox Template itemsource?

Here is my slice of codes

MyList myList = new MyList(); MyItem myData = new MyItem(); myData.id = "DB123456"; .... myList.Insert(0,myData); Binding binding = new Binding(); binding.Source = myList;

uiList.SetBinding(ListBox.ItemsSourceProperty, binding);

Here is the Data Template, how to change the hardcoded items list to get from database, thanks.

<DataTemplate x:Key="MyList" DataType="MyList">

<Border BorderThickness="0,0,0,1" BorderBrush="#ff849cb1" Margin="2,1">

<ComboBox Name="comboBox1" Height="23" HorizontalAlignment="Center" VerticalAlignment="Top" Width="60" Foreground="Black" SelectionChanged="comboBox1_SelectionChanged"> 

<ComboBox.Resources>

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue"/>

</ComboBox.Resources>

<ComboBoxItem Content="Mary" />

                        <ComboBoxItem Content="Peter" />

</ComboBox>

</Border>

</DataTemplate>




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>