allow only distinct values in ComboBox
Posted
by
Ravinder Gangadher
on Stack Overflow
See other posts from Stack Overflow
or by Ravinder Gangadher
Published on 2012-11-03T10:50:24Z
Indexed on
2012/11/03
11:00 UTC
Read the original article
Hit count: 167
In my project, I am trying to populate ComboBox
from DataSet
. I succeeded in populating but the values inside the ComboBox
are not distinct (Because it just showing the values present in DataSet
). I cant bind the ComboBox
to DataSet
because I am adding "Select" text at first of populating the values. Here is my code.
ComboBox --> cmb
DataSet --> ds
DataSet Column Name --> value(string)
cmb.Items.Clear();
cmb.Items.Add("Select");
for (int intCount = 0; intCount < ds.Tables[0].Rows.Count; intCount++)
{
cmb.Items.Add(ds.Tables[0].Rows[intCount][value].ToString());
}
cmb.SelectedIndex = 0;
My question is how to allow distinct values (or restrict duplicate values) inside the ComboBox.
© Stack Overflow or respective owner