I am making a point of sale program which has basically a listview and product entrance. When the person enter the same product, this program should increase the quantity of the existing product on the list, not creating a new whole row.
So, my question is that how to dynamically add items in ListView in WPF. I mean, I would like to choose a specific row of a listview to get a specific cell on it. But I don't want to get the selected row. Just a specific row.
Let me describe it as a matrix: lvProduct[0][2]. This should give me second cell of the first row. How to apply it in C# WPF?
My code is as follows:
private void btnProductAdd_Click(object sender, RoutedEventArgs e)
{
bool addNewProductLine = true;
decimal totalSalePrice = Convert.ToDecimal(txtProductPrice.Text) * Convert.ToInt32(txtProductAmount.Text);
for (int i = 0; i < lvProducts.Items.Count; i++)
{
ProductBLL product = lvProducts.Items.GetItemAt(i) as ProductBLL;
if (product.BarcodeRetail== txtProductBarcode.Text)//If there is already the same item on the list, then confirm to add them together or not.
{
if (MessageBox.Show("There is already the same item in the list. Would you like to sum them?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
product.Amount +=Convert.ToInt32(txtProductAmount.Text);
addNewProductLine = false;
break;
}
}
}
List<ProductBLL> items = new List<ProductBLL>();
items.Add(new ProductBLL() { BarcodeRetail=txtProductBarcode.Text, Name = txtProductName.Text, UnitRetail = Convert.ToInt32(cboProductUnit.SelectedIndex), SalePrice = Convert.ToDecimal(txtProductPrice.Text), Amount = Convert.ToInt32(txtProductAmount.Text), TotalSalePrice = totalSalePrice});
//lvProducts.ItemsSource = items; This code renew the listview completely. That means, it erases old datas and writes the new ones.
if (addNewProductLine == true)
{
lvProducts.Items.Add(items);
}
ClearProductEntranceTextBox();
//items[0].BarcodeRetail = "EXAMPLECODE"; This code can change the 0th row's data on the column called BarcodeRetail.
}
Unfortunatelly this code does not work :/
Thank in advance everyone!