So I created a ListView using Dataset, i.e. selecting ListView option for the table in the Data Sources Window and dragging it onto my interface.
Each of the columns have a Mode for binding (TwoWay/OneWay etc). They all got pre set to TwoWay i.e. here is a snippet of my ListView in the xaml file:
<ListView x:Name="cbTableListView" Grid.ColumnSpan="2" ItemsSource="{Binding}" Margin="16,73,16,135"
SelectionChanged="onChangeRecord" SelectionMode="Single">
<ListView.ItemContainerStyle>
<Style>
<Setter Property="Control.HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Control.VerticalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn x:Name="_idColumn" Header="ID" Width="60">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Margin="10,-1,-6,-1" Text="{Binding _id, Mode=OneWay}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="company_nameColumn" Header="Company Name" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Margin="-6,-1" Text="{Binding company_name, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="contact_nameColumn" Header="Contact Name" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Margin="-6,-1" Text="{Binding contact_name, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
...and so on for the remaining columns
I need to have it so the user can edit the rows in the listview, press save changes, and have changes saved to the database. I'm assuming this is what the 'TwoWay' is all about? I've tried using the acceptchanges method on the dataset, doesnt seem to work:
cBDataSet.AcceptChanges();
cBDataSetcbTableTableAdapter.Fill(cBDataSet.cbTable);
cbTableViewSource = ((System.Windows.Data.CollectionViewSource) (this.FindResource("cbTableViewSource")));
cbTableViewSource.View.MoveCurrentToFirst();
Anyone any ideas? Not sure what i'm doing wrong
Thanks