Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

How to create combobox template column in code behind.

$
0
0

Hi,

I am in serious need of some help on the below issue and already i spent more than 1 day on this.

I have followed the below post by colin and was able to create a silverlight datagrid with dynamically created columns columns based on number of fields in itemsource and binding the same with dynamic data. So everything happens on runtime here.

http://www.scottlogic.com/blog/2009/04/22/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged.html 

My problem here is i need to create different columns(dropdown, datetime etc) based on the field type from the itemsource. I am able to create different column but unable to bind the source to it. Below is the code i used to create a dynamic combobox column.

if (propertyType.ToLower() == "choice")
                {
                    return new DataGridTemplateColumn()
                    {
                        Header = property,                       
                        CellTemplate = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Load(@"<DataTemplate 
                       xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                        xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
                        xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'    
                        xmlns:sdk='http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'>                                                    
                       <ComboBox SelectedValue=""{Binding Path=Data,Converter={StaticResource _rowIndexConverter},ConverterParameter=property,Mode=TwoWay}"">               
                       <ComboBoxItem>" + data1 + "</ComboBoxItem><ComboBoxItem>" + data1 + "</ComboBoxItem>  </ComboBox></DataTemplate>"),

};

}

This combobox does not recognize the itemsource and that is the reason i hardcoded it. When i run this code i am getting "XamlParseException" error. If i remove the convertor from the combobox tag i am not getting any error but the bound value is not shown on the combobox and also if we change selection in combobox the same is not getting updated back to its itemsource.

So i want to create a combobox template column for the logic given in the above provided link. I doubt that the way i set the converter and converter parameter for the combobox is not right and also no idea why itemsource is also not working.

Any suggestions would be of Great help. Thanks in advance !!!





Viewing all articles
Browse latest Browse all 1083

Trending Articles



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