- If you don’t want to add the Everyone item to your data source, you can do the following:
Code snippet
comboBox1.Text = "All";
It sets the text displayed in the comboBox to the assigned value, but without changing the elements in the comboBox and the associated data source.
- You can also add "Everything" to your data source. But you should do it like this:
Code snippet
private void button1_Click(object sender, EventArgs e)
{
DataRow dataRow = dataTable.NewRow();
dataRow["ItemId"] = "All";
dataTable.Rows.InsertAt(dataRow, 0);
comboBox1.SelectedIndex = 0;
}
The easiest way is to insert a line into your ds.Tables [0], which
ds = StockDAL.BindItemId();
DataRow dataRow = ds.Tables[0].NewRow();
dataRow["ItemId"] = "All";
ds.Tables[0].Rows.InsertAt(dataRow, 0);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "ItemId";
comboBox1.ValueMember = "ItemId";
comboBox1.selectedIndex=0;
hope this solves ur problem
source
share