2016-06-13 5 views
0

약간의 작업을 해본 결과 많은 코드가 없습니다. Meds.xaml 및 Meds.xaml.cs 코드를 보여 드리겠습니다. 데이터를 Listview에 바인딩하는 데 도움이되는지 확인하십시오. 기본적으로 폼이 채워지고 버튼이 클릭되어 데이터베이스에 추가되고 ListView가 업데이트됩니다.Windows Universal Apps - Listview에서 SQLite 데이터 표시

<TextBlock x:Name="textBlock1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Medication Name:" VerticalAlignment="Top" Margin="43,255,0,0" Foreground="#FFC6C6C6" FontSize="18.667"/> 
     <TextBox x:Name="medname_box" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="265,248,0,0" Width="186"/> 
    <TextBlock x:Name="textBlock1_Copy" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Medication Total Dose:" VerticalAlignment="Top" 

....와에와

<ListView x:Name="listView" HorizontalAlignment="Left" Height="464" VerticalAlignment="Top" Width="283" Margin="655,217,0,0" SelectionChanged="listView_SelectionChanged"/> 

에 난 여기 약을의 데이터 지금

</Grid> 

을 표시 할 Meds.xaml 경우 .xaml.cs

public sealed partial class Meds : Page 
{ 
    string path; 
    SQLite.Net.SQLiteConnection conn; 

    public Meds() 
    { 
     this.InitializeComponent(); 
     path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, 
      "meds.sqlite"); 
     conn = new SQLite.Net.SQLiteConnection(new 
      SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path); 
     conn.CreateTable<Medications>(); 

     var query = conn.Table<Medications>(); 
     string id = ""; 
     string MedName = ""; 
     string MedDose = ""; 
     int AM; 
     int Noon; 
     int Supper; 
     int Night; 
     int PRN; 
     int Other; 
     string WhatFor = ""; 
    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     if (Frame.CanGoBack) 
     { 
      Frame.GoBack(); 
     } 


    } 

    private void button2_Click(object sender, RoutedEventArgs e) 
    { 

     var z = conn.Insert(new Medications() 
     { 


      MedName = medname_box.Text, 
      MedDose = meddose_box.Text, 

은 체크 박스를 파악 아직 ...

  // AM = , 
     // Noon = "", 
     // Supper = "", 
     // Night = "", 
     // PRN = "", 
     // Other = "", 
     WhatFor = whatfor_box.Text 
     }); 

     //   var query = conn.Table<Medications>(); 
     //    string id = ""; 
     //    string CurrentMood = ""; 


     //    foreach (var message in query) 
     //    { 
     //  id = id + " " + message.Id; 
     //   CurrentMood = message.MedName; 

     //   } 
    } 

     private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 

    } 
} 
} 
public class Medications 
{ 
    [PrimaryKey, AutoIncrement] 
    public int Id { get; set; } 
public string MedName { get; set; } 
public string MedDose { get; set; } 
public int AM { get; set; } 
public int Noon { get; set; } 
public int Supper { get; set; } 
public int Night { get; set; } 
public int PRN { get; set; } 
public int Other { get; set; } 
public string WhatFor { get; set; } 

}

+0

는 그리고 당신의 질문은 ...? 제발 좀 더 정확하고 코멘트 물건과 같은 불필요한 코드를 제거하십시오. –

답변

1

을 내가 목록보기에 데이터 바인딩에 약간의 도움을받을 수 있는지 확인하지 않았습니다. 기본적으로 폼이 채워지고 버튼이 클릭되어 데이터베이스에 추가되고 ListView가 업데이트됩니다.

:

귀하의 설명에 따르면, 당신이 위에 제공된 코드를 기반으로, 나는 Binding 및 참조 용 SQLite.Net-PCL을 사용하여 ListView에있는 SQLite는 데이터를 표시하는 방법을 보여줍니다 간단한 샘플을 만들었습니다 Meds.xaml :

<StackPanel> 
    <TextBox Header="Medication Name: " x:Name="medname_box" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="186" /> 
    <TextBox Header="Medication Total Dose: " x:Name="meddose_box" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="186" /> 
    <TextBox Header="What For: " x:Name="whatfor_box" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="186" /> 
    <Button x:Name="btnAdd" Content="Add" Click="btnAdd_Click" Width="186" Margin="0,5" /> 
    <Button x:Name="btnBack" Content="Back" Click="btnBack_Click" Width="186" Margin="0,5" /> 
    <ListView Header="Medications" x:Name="myList" Background="White" HorizontalAlignment="Left" Width="400"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <Grid Width="400"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
        <!--Bind data to ListView Item, here I just bind three items for Medications, you can add other items if needed--> 
        <TextBlock x:Name="medName" Text="{Binding Path=MedName}" TextWrapping="Wrap" /> 
        <TextBlock Grid.Column="1" x:Name="medDose" Text="{Binding Path=MedDose}" TextWrapping="Wrap" /> 
        <TextBlock Grid.Column="2" x:Name="whatFor" Text="{Binding Path=WhatFor}" TextWrapping="Wrap" /> 
       </Grid> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
</StackPanel> 

Meds.xaml.cs :

여기

Entire Sample이며, 다음과 같은 출력입니다 : enter image description here

+0

위대한 작품, 감사합니다! – sandorfalot

관련 문제