大家好。我正在使用ListView
带有两列的 a 来读取 a 中的表格SQL server
。所以一切都是正确的,当我拥有它时ListBox
,但现在我更改为ListView
并制作了列,出现了问题,行进入但没有文本,所以它只是向我显示一个ListView
可滚动的空白。
这是XAML
针对ListView
:
<ListView Height="315" HorizontalAlignment="Left" Margin="26,15,0,0" Name="listView1" VerticalAlignment="Top" Width="324">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Title}" Header="Title" Width="240"/>
<GridViewColumn DisplayMemberBinding="{Binding Price}" Header="Price" Width="75"/>
</GridView>
</ListView.View>
</ListView>
这是TextChanged
事件中调用的代码以从服务器表中调用它。
public void addtoList()
{
cn.Open();
String cmdString = "Select Title, Price from tblCart";
SqlCommand cmd = new SqlCommand(cmdString, cn);
SqlDataReader dr = cmd.ExecuteReader();
double subT = 0;
double tax = 1.09;
double total = 0;
while (dr.Read())
{
int count = dr.FieldCount - 1;
for (int i = 0; i < count; i++)
{
listView1.Items.Add(dr["Title"].ToString());
listView1.Items.Add(dr["Price"].ToString());
subT += Convert.ToDouble(dr["Price"]);
}
}
total = Convert.ToDouble(subT * tax);
subTotal.Text = subT.ToString();
totalBlk.Text = total.ToString();
cn.Close();
}
任何有关如何解决此问题的信息将不胜感激!