Translate

> > Silverlight Datagrid Combobox Value Bind and get data

Silverlight Datagrid Combobox Value Bind and get data

Posted on Saturday, April 12, 2014 | No Comments

1. Namespace for data grid           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"


2.     <sdk:DataGrid Name="dataGrid"  AutoGenerateColumns="False" Width="650"
                                  ScrollViewer.VerticalScrollBarVisibility="Auto" Height="150" >
                        <sdk:DataGrid.Columns>

                            <sdk:DataGridTemplateColumn Header="Pay Mode" Width="100">
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox  Name="cmbPayMode"
                                                  HorizontalAlignment="Left"
                                                  VerticalAlignment="Top" ItemsSource="{StaticResource oBillTypeList}"
                                                  DisplayMemberPath="CatName" SelectedValuePath="CatName"
                                                   SelectedItem="{Binding PayMode, Mode=TwoWay}"
                                                   SelectionChanged="cmbPayMode_SelectionChanged"
                                                  Width="80">
                                        </ComboBox>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>


                           
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>


3.   set data grid datasource by your desire datasource



  dataGrid.ItemsSource = oList;

4.  now for combobox data source in your class constructor , before initialize code add this code
            this.Resources.Add("oBillTypeList", oBillTypeList);
oBillTypeList  is a   ObservableCollection. other wise it cannnot load data from wcf ria service result set.

5.  to get data from your combobox or any control you can parse data from this code. or you can set bindmode two way.

foreach (AdvanceCollection p in oList)
                {
                    ComboBox cmbPayMod = dataGrid.Columns[0].GetCellContent(p) as ComboBox;
                    TextBox txtMode = dataGrid.Columns[2].GetCellContent(p) as TextBox;
                   
                }

Leave a Reply

Powered by Blogger.