在這種情況下,怎麼過濾掉comboBox裡面的重復項...
看代碼:
public class ComboBoxItem
{
//為ComboBox添加value和text值
private string _text=null;
private object _value=null;
public string Text{get{return this._text;} set{this._text=value;}}
public object Value{get {return this._value;}
set{this._value=value;}}
public override string ToString()
{
return this._text;
}
}
private void addComboBox()
{
DataView dataView = new DataView();
dataView = Agent_DataLayer.DsPositionAndStaff.StaffAndPosition.Copy().DefaultView;
dataView.RowFilter = "MarkId <> 0";
foreach(DataRowView drv in dataView)
{
int strVal = int.Parse(drv["staffId"].ToString());
string strText = drv["ItemFull"].ToString().Trim();
//(看下面一段,問題就在這裡,程序運行後,依然出現重復的strText)
if(!this.cmbStaffInfo.Items.Contains(strText))//過濾重復 {
ComboBoxItem newItem = new ComboBoxItem();
newItem.Text = strText; //添加text值
newItem.Value = strVal; //添加value值
this.cmbStaffInfo.Items.Add(newItem);
}
}
}