How to add a row to databound combobox?

I have a combobox and I need the first row to be set as default.

This is my code

 cbBrandForModel.DisplayMember = "BrandName";
 cbBrandForModel.ValueMember = "BrandID";
 cbBrandForModel.DataSource = dataTable;

I need to add this:

cbBrandForModel.DisplayMember = "Select Brand";
cbBrandForModel.ValueMember = "0";

Can anyone tell me how to do it?

EDIT: I managed to add a new row in my DataTable.

var dataRow = dataTable.NewRow();
                dataRow["BrandID"] = "0";
                dataRow["BrandName"] = "--Select Brand--";
                dataTable.Rows.Add(dataRow);

Now I need to set this row as the first row in the combobox.

Answers


If the (SelectedValue of the) ComboBox is not databound, all you need is to set `cbBrandForModel.SelectedIndex = 0;'


I agree with the answer regarding SelectedIndex.

In addition your second code snippet, where you set DisplayMember and ValueMember again, overwrites the first snippet. This is not going to have the effect you intend.


Need Your Help

setAttribute() method for WebElement

java c# python selenium selenium-webdriver

In this question both answers used setAttribute() as WebElement functionality. However, I couldn't find this method in the Java, C# nor Python documentation, only getAttribute(). Trying to call this

Axigen Disable 550 Messages

smtp messages

I was performing some SPAM Testing on an Axigen Server, when I discovered a flaw which I would like to know if it can be disabled.