Hey guys. I am using a ListView with two columns to read a table off a SQL server. So everything was right, when I had it a ListBox, but now that I changed to ListView and made columns something has gone wrong and the rows are coming in but there is no text, so it is just showing me a blank ListView that is scrollable.
Here is the XAML for the 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>
And this is the code being called on the TextChanged event to call it in from server table.
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();
}
Any information on how to fix this will be greatly appreciated!