从绑定到数据集的组合框中删除重复项 [英] Remove duplicates from combobox which is bind to dataset
问题描述
我的专案中有 xml档案。我正在通过combobox cbProduct
下面的代码读取文件。问题是 cbProduct
显示重复的文本值。如何使它们独特?
I have a xml file in my project. I am reading the file through the below code in to combobox cbProduct
. The problem is that the cbProduct
is displaying duplicate text values. How to make them distinct?
我已经浏览了一些链接但有方法的方法是不相关的数据集。
我实现了下面的代码:
I have gone through some links but there way of approach is not related to dataset.
I implemented the below code:
DataSet ds = new DataSet();
ds.ReadXml(@"..\..\stock.xml");
cbProduct.DataSource = ds.Tables[0];
cbProduct.DisplayMember = "productname";
可选:如果您有时间,过程,因为我是新的.net或提供链接至少指向(不是msdn)。
optional: If you have time it will be appreciable if you explain the process because I am new to .net or provide a link atleast to refer (not msdn).
请帮助。
提前感谢。
Please Help.
Thanks in advance.
推荐答案
执行此操作
DataSet ds = new DataSet();
ds.ReadXml(@"..\..\stock.xml");
DataTable dt = ds.Tables[0].DefaultView.ToTable(true, "productname");
cbProduct.DataSource = dt;
cbProduct.DisplayMember = "productname";
第三个代码行创建一个基于productname列具有不同值的新表。更多信息,请阅读此
Third code line creates a new table which will have distinct values based on productname column. For More read this
此代码是此处
这篇关于从绑定到数据集的组合框中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!