I'm developing a WPF application with MVVM pattern.
I'm populating data to gridview and on selection, I populate to textbox,combobox to edit the contents. then Save the data.
Now I want to add new data to the grid view. User input to textbox,combo box should be add to grid view and the i need to save it to data base.
my XMAL is as follows:
<Grid Height="444" Width="486">
<Label Content="Script" Height="28" HorizontalAlignment="Left" Margin="13,36,0,0" Name="lblScript" VerticalAlignment="Top" />
<TextBox Height="142" HorizontalAlignment="Left" Margin="75,38,0,0" Name="txtScript" VerticalAlignment="Top" Width="380" Text="{Binding Script_Text}"/>
<Button Content="Add" Command="{Binding SaveData}" Height="23" HorizontalAlignment="Left" Margin="284,409,0,0" Name="btnSave" VerticalAlignment="Top" Width="75" />
<Button Content="Reset" Command="{Binding ClearData}" Height="23" HorizontalAlignment="Left" Margin="380,409,0,0" Name="btnReset" VerticalAlignment="Top" Width="75" />
<DataGrid ItemsSource="{Binding Path=Param}" HeadersVisibility="Column" SelectionMode="Single"
AlternatingRowBackground="Gainsboro" Background="White" AutoGenerateColumns="False"
ItemContainerStyle="{StaticResource itemstyle}" CanUserAddRows="True" GridLinesVisibility="None"
Height="150" HorizontalAlignment="Left" HorizontalContentAlignment="Left" IsEnabled="True"
IsReadOnly="True" Margin="75,200,0,0" Name="dgMain" RowHeight="23" VerticalAlignment="Center"
VerticalContentAlignment="Center" Width="380" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding EditData}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Name}" Header="Parameter" Width="140" />
<DataGridTextColumn Binding="{Binding Path=Type}" Header="Type" Width="100" />
<DataGridTextColumn Binding="{Binding Path=Value}" Header="Value" Width="120" />
</DataGrid.Columns>
</DataGrid>
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="75,186,0,0" Name="lblName" VerticalAlignment="Top" />
<TextBox Height="23" Text="{Binding SelectedItem.Name, ElementName=dgMain}" HorizontalAlignment="Left" Margin="75,213,0,0" Name="txtName" VerticalAlignment="Top" Width="110" />
<Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="191,186,0,0" Name="lblType" VerticalAlignment="Top" />
<ComboBox Height="23" Text="{Binding SelectedItem.Type, ElementName=dgMain}" HorizontalAlignment="Left" Margin="191,213,0,0" Name="cboType" VerticalAlignment="Top" Width="110" ItemsSource="{Binding}">
<ComboBoxItem Content="integer" />
<ComboBoxItem Content="double" />
<ComboBoxItem Content="string" />
</ComboBox>
<Label Content="Value" Height="28" HorizontalAlignment="Left" Margin="307,186,0,0" Name="lblValue" VerticalAlignment="Top" />
<TextBox Height="23" Text="{Binding SelectedItem.Value, ElementName=dgMain}" HorizontalAlignment="Left" Margin="307,213,0,0" Name="textBox1" VerticalAlignment="Top" Width="110" />
<TextBlock HorizontalAlignment="Left" Margin="428,15,0,0" Height="32">
<ToggleButton x:Name="Add" Focusable="False" Command ="{Binding AddNew}" Style="{StaticResource SMToggle}" >
<Image Source="/Image/Add.png" Width="16" Height="16" />
</ToggleButton>
</TextBlock>
</Grid>
Please help me. SN