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

WPF VB NET DataTemplate binding and combobox from another source

$
0
0

hi, I really don't know how describe my problem since am new in this WPF. please help me..

the goal is that the user can map columns from xml file and say ok that column I want to be mapped with this column from my database table and then import records to my database according to the xml rows

Now... I have create a user control with 1 label and one combobox
the label is used to to display the column Name from My dataBase
The Combobox is normally used to display the column from the xml file that the user want to select and map

that user control is used as a dataTemplate inside ItemsControl

I have a DataTable which contains rows with my column names from my sql database 

by using XAML I said to the label to bind to the column I want and then I set in  the code behind MyItemsControl1.ItemsSource=MyDataTable (fine so far)

when I  run the application I can see a list of 5 rows ( which are the number of columns in my SQL table) and the label with the correct value of the column Name

now about the combobox I have another DataTable which contains onother list of rows and 1 column the rows contain the value of the column name read by the xml  

this is my XAML for ItemsControl

<ItemsControl x:Name="ItemsControl1" Margin="36,76,0,0" ><ItemsControl.ItemTemplate><DataTemplate  ><local1:MyDataTemplate HorizontalAlignment="Left" ></local1:MyDataTemplate></DataTemplate></ItemsControl.ItemTemplate></ItemsControl>

This MyXAML for MyDataTemplate ( UserControl)

<UserControl x:Class="MyDataTemplate"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="53" Width="290"><Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"><Label Content="{Binding Path=COLUMN_NAME}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="27" Width="78" Margin="0,-2,0,0" BorderThickness="0,2,0,0" Background="{x:Null}"/><Border Margin="0,28,0,4" BorderBrush="Black" BorderThickness="0,0,0,1" ><ComboBox  x:Name="cb" VerticalAlignment="Top" Background="{x:Null}" BorderBrush="{x:Null}" Height="20"/></Border></Grid></UserControl>

In CodeBehind

Private Sub ShowItems() Dim DS As New DataSet DS.ReadXml(FileName) Dim MyOthersourceColumns As New DataTable("MyOtherSourcecolumns") MyOthersourceColumns.Columns.Add("Column_Name_FromOthersource") For Each c As DataColumn In DS.Tables(0).Columns MyOthersourceColumns.Rows.Add(c.ColumnName) Next 'Read columns from sql

Dim DT As DataTable = GetData(" SELECT Column_Name,'' as MyMapColumn FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'passwords'") ItemsControl1.ItemsSource = DT.DefaultView 'Here i want to say to the combobox that your source is the MyOthersourceColumns End Sub

I truly apology if I don't explain correct . am new to this wpf . so please let me know to explain again if is not well clear.

to be clear a little more I have attach an image of the part I describe above


the labels are the columns from my database, the comboboxes are empty because I don't know how to bind to the datatable I describe above


stelios ----------





Viewing all articles
Browse latest Browse all 18858