wpf + binding dynamically + delete,update,add new rows

Jul 7, 2011 at 10:46 AM

I am new to WPF and i need to get the below requirment can someone help me



Below is the XAML code wrriten


<my:DataGrid AutoGenerateColumns="False" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="150,5,0,0"

                             Name="dataGridReq" ItemsSource="{Binding}"










                             CanUserAddRows="False" CanUserDeleteRows="True" MouseDoubleClick="dataGridReq_MouseDoubleClick">


                        <my:DataGridTemplateColumn Header="Type" MaxWidth="200">



                                    <StackPanel Orientation="Horizontal">

                                        <ComboBox ItemsSource="{Binding Path=RequirmentType}" Width="200" 

                                              SelectedValue="{Binding Path=ItemId, Mode=TwoWay}" DisplayMemberPath="ItemName" >








                        <my:DataGridTemplateColumn Header="Description">



                                    <TextBox Width="100" Height="20" TextWrapping="Wrap" Name="txtRequirement">








Code behind file

public class RequirmentList



            public int ItemId { get; set; }

            public int ListId { get; set; }

            public string ItemName { get; set; }

            private ListItems[] _requirmentType;

            public string Description { get; set; }


            public ListItems[] RequirmentType


                get { return _requirmentType; }

                set { _requirmentType = client.GetListItems(client.GetListsById(33)); }







on load intializing i am doing




List<RequirmentList> ticketsList = new List<RequirmentList>


                    new RequirmentList{ RequirmentType= client.GetListItems(client.GetListsById(33))}


                dataGridReq.ItemsSource = ticketsList;



with the above code i am able to bind the combobox. but When i change xaml as below


<my:DataGridComboBoxColumn Width="Auto" Header="Type" SelectedValueBinding="{Binding ItemId}"



                                                  ItemsSource="{Binding Path=DataContext.RequirmentType}">




<my:DataGridTextColumn Width="Auto" Header="Description" Binding="{Binding Path=Description}"/>



I dont see the binding working properly,and also the when i add new row to the datagrid i dont see the bindings for new row. New row is getting created with out the binding values in combobox.

I need to add,delete rows. Even with the data update,create new rows,delete i need to do.

Also the combobox is only binding column and the text column is just the data which user enters.But when save is clicked both columns data should be saved.

I knw this is something basic in .net but coming to WPF i am struggling

Please help me!!!!