我正在开发 Windows 商店应用程序。我正在使用 sqlite 数据库,我想将 select 查询的结果放入 listview。我的列表视图有网格,这些网格内有文本框。但是,当我给它们命名时,我无法在 c# 中定位这些文本框。这是项目中的代码示例:第一个 sqlite 查询:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
string DBPath = string.Empty;
DBPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "mydb.s3db");
using (var db= new SQLite.SQLiteConnection(DBPath))
{
var query= db.Table<company>();
var result= query.ToList();
foreach( var x in result )
{
company frm= new company();
//addition to listview...
}
}
}
除了输入列表视图之外,一切都在上面完美运行。我已经用列表视图之外的文本块对其进行了测试。
和 xml:
<ListView Name="lv" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" Grid.Row="3" Grid.RowSpan="11" Grid.ColumnSpan="8">
<ListView.HeaderTemplate>
<DataTemplate>
<Grid Loaded="gHeader_Loaded">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="2" Grid.Column="0" Text="company no" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="company name" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="phone" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="3" Text="fax" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="4" Text="address" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="5" Text="state" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="6" Text="city" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<ComboBox Grid.Row="2" Grid.Column="7" HorizontalAlignment="Center" VerticalAlignment="Center">
<ComboBoxItem Content="test1"></ComboBoxItem>
<ComboBoxItem Content="test2"></ComboBoxItem>
<ComboBoxItem Content="test3"></ComboBoxItem>
<ComboBoxItem Content="test4"></ComboBoxItem>
<ComboBoxItem Content="test5"></ComboBoxItem>
</ComboBox>
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Loaded="gHeader_Loaded">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock x:Name="test" Grid.Row="2" Grid.Column="0" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="3" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="4" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="5" Text="" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
很抱歉,这篇文章很长,我想提供有关该程序的详细信息,然后也许您可以看到出了什么问题。我将不胜感激任何帮助/反馈。
致以我的问候...