从一个组合框传递ID来填充在WPF第二个组合框中 [英] Passing id from one combobox to populate second combo box in WPF

查看:157
本文介绍了从一个组合框传递ID来填充在WPF第二个组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何传递的categoryId在第一个组合框到数据库中选定的类别名称,它将填充产品在第二个组合框/

how do i pass the categoryId for the selected CategoryName in the first combo box to the database, which would populate the products in the second combo box /

表结构低于

Table_Category
类别ID
CategoryyName

Table_Category CategoryId CategoryyName

Table_Product
产品编号
产品名称
类别ID
productSku,则
ProductUnit

Table_Product ProductId ProductName CategoryId ProductPrice ProductUnit

谢谢,
侯赛因帕特尔

Thanks, Hussain Patel

推荐答案

有关使用ADO.NET(code)的第一个组合框(cmbcategory),获得类别对象(含的categoryId和类别名称),并绑定到的ItemSource第一个组合框的财产(cmbcategory)

for the first combo box (cmbcategory) using ADO.NET (code), get category object (containing the categoryId and categoryName) and bind to itemsource property of first combo box (cmbcategory)


  cmbcategory.ItemsSource = categories.DefaultView;

Example cmbcategory.ItemsSource = categories.DefaultView;

在XAML code为cmbcategory添加两个属性的DisplayMemberPath和SelectedValuePath。分配的类别名称和类别ID给他们。

In the xaml code for the cmbcategory add two attributes DisplayMemberPath and SelectedValuePath. assign the the "CategoryName" and "CategoryID" to them. Example

现在您可以检索在cmbcategory选择的项目类别ID,如下
  字符串TMP = cmbcategory.SelectedValue.ToString();

Now you can retrieve the category id for the item selected in the cmbcategory,as below string tmp = cmbcategory.SelectedValue.ToString();

这可被传递到ADO.NET SQL命令对象和产品可以检索和bindded到cmbproduct组合框,如下

This can be passed to the ADO.NET SQL command object and products can be retrieved and the bindded to the cmbproduct combo box as below

cmbproduct.ItemsSource = products.DefaultView;

cmbproduct.ItemsSource = products.DefaultView;

因此​​,对于在第一cmbcategory产品填充在cmbproducts选择每个类别

Thus for each category selected in the first cmbcategory the products are populated in the cmbproducts.

谢谢,
侯赛因

Thanks, hussain

这篇关于从一个组合框传递ID来填充在WPF第二个组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆