Как выбрать конкретную строку списка в C# WPF?(Не выбранная строка.)
Я делаю программу для торговых точек, в которой есть в основном просмотр списка и ввод продукта. Когда человек вводит тот же продукт, эта программа должна увеличивать количество существующего продукта в списке, а не создавать новую целую строку.
Итак, мой вопрос в том, как динамически добавлять элементы в ListView в WPF. Я имею в виду, я хотел бы выбрать определенную строку списка, чтобы получить в ней определенную ячейку. Но я не хочу получать выбранную строку. Просто конкретная строка.
Позвольте мне описать это как матрицу: lvProduct[0][2]. Это должно дать мне вторую ячейку первой строки. Как применить это в C# WPF?
Мой код выглядит следующим образом:
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.
}
К сожалению, этот код не работает:/
Заранее всем спасибо!