Forums - C# Corner

Forum guidelines
ABHIJIT POOJARI

ABHIJIT POOJARI

  • 1.8k
  • 19
  • 750

Window 8.1 app development

Oct 26 2017 1:01 AM
I have use sqlite and visualstudio 2015. I have displayed the required data using listview.
Now i want to display data of only the selected item in listview when i click the display the data(Button).
 
when i click showdata button(btnAdd_Click) listview is displayed.
 
Display.xaml
  1. <Grid Background="Gray">  
  2. <Button x:Name="btn" Click="btnAdd_Click" Content="Showdata" Width="200" Margin="900,43,0,687" Background="#FF040404" />  
  3. <ListView Header="Detailss" x:Name="myList" HorizontalAlignment="Left">  
  4. <ListView.ItemTemplate>  
  5. <DataTemplate>  
  6. <StackPanel Orientation="Vertical" Height="150" Width="200" Background="White">  
  7. <TextBlock x:Name="username" HorizontalAlignment="Left" Text="{Binding Username}" TextWrapping="Wrap" Foreground="Black" />  
  8. <TextBlock x:Name="password" Text="{Binding Password}" TextWrapping="Wrap" Foreground="Black" />  
  9. <TextBlock x:Name="name" Text="{Binding Name}" TextWrapping="Wrap" Foreground="Black" />  
  10. <TextBlock x:Name="address" Text="{Binding Address}" TextWrapping="Wrap" Foreground="Black"/>  
  11. <Button x:Name="btn1" Content="Display This Data" Background="#FFA68A8A" Foreground="#FF060606" Click="btn1Add_Click"/>  
  12. </StackPanel>  
  13. </DataTemplate>  
  14. </ListView.ItemTemplate>  
  15. </ListView>  
 
Display.xaml.cs
  1. string DB_Path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Winapp.sqlite");  
  2. private void btnAdd_Click(object sender, RoutedEventArgs e)  
  3. {  
  4. ObservableCollection<RegisterTable> obsregtable = new ObservableCollection<RegisterTable>();  
  5. using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DB_Path))  
  6. {  
  7. List<RegisterTable> RegisterData = conn.Query<RegisterTable>("select * from RegisterTable");  
  8. foreach (var item in RegisterData)  
  9. {  
  10. obsregtable.Add(new RegisterTable() { Id = item.Id, Name = item.Name, Username = item.Username, Password = item.Password, Address = item.Address });  
  11. }  
  12. myList.ItemsSource = obsregtable;  
  13. }  
  14. private async void btn1Add_Click(object sender, RoutedEventArgs e)  
  15. {  

Answers (1)