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}"

                             HeadersVisibility="Column"

                             IsSynchronizedWithCurrentItem="True"

                             Background="Transparent"

                             RowHeaderWidth="25"

                             RowHeight="40"                    

                             RowBackground="White"

                             AlternatingRowBackground="LightGray"

                             AlternationCount="2"

                             SelectionUnit="CellOrRowHeader"

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

                    <my:DataGrid.Columns>

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

                            <my:DataGridTemplateColumn.CellTemplate>

                                <DataTemplate>

                                    <StackPanel Orientation="Horizontal">

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

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

                                        </ComboBox>

                                    </StackPanel>

                                </DataTemplate>

                            </my:DataGridTemplateColumn.CellTemplate>

 

 

                        </my:DataGridTemplateColumn>

                        <my:DataGridTemplateColumn Header="Description">

                            <my:DataGridTemplateColumn.CellTemplate>

                                <DataTemplate>

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

                                    </TextBox>

                                </DataTemplate>

                            </my:DataGridTemplateColumn.CellTemplate>

                       </my:DataGridTemplateColumn>

                </my:DataGridTemplateColumn>

                    </my:DataGrid.Columns></my:DataGrid>

 

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}"

                                                  SelectedValuePath="ItemId"

                                                  DisplayMemberPath="ItemName"

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

 

                        </my:DataGridComboBoxColumn

 

<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!!!!