Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set first index as blank in combobox

I have a combobox that is bound with a datasource. In this combobox I have to add a blank field at index 0.

I have written following code for getting records.

 public List<TBASubType> GetSubType(int typ)
        {
            using (var tr = session.BeginTransaction())
            {
                try
                {
                    List<TBASubType> lstSubTypes = (from sbt in session.Query<TBASubType>()
                                                    where sbt.FType == typ
                                                    select sbt).ToList();


                    tr.Commit();
                    return lstSubTypes;
                }
                catch (Exception ex)
                {
                    CusException cex = new CusException(ex);
                    cex.Write();
                    return null;
                }
            }
        }

After this it bind with combobox with data binding source as below code.

M3.CM.BAL.CM CMobj = new M3.CM.BAL.CM(wSession.CreateSession());
                lstSubTypes = CMobj.GetSubType(type);
                this.tBASubTypeBindingSource.DataSource = lstSubTypes;
like image 911
Amit Kumar Avatar asked Aug 07 '13 13:08

Amit Kumar


People also ask

How do I index my ComboBox?

The Combobox widget allows you to create a dropdown list in which the list of items can be selected instantly. However, if you want to get the index of selected items in the combobox widget, then you can use the get() method. The get() method returns an integer of the selected item known as the index of the item.

How do I disable text in ComboBox?

Right click the Combo Box you want to disable typing, then click Properties from the right-clicking menu. See screenshot: 3. In the Properties dialog box, select 2 – fmStyleDropDownList from the Style drop-down list, and then close this dialog box.


1 Answers

If you just want to select nothing initially, you can use

comboBox1.SelectedIndex=-1;
like image 184
Energy Avatar answered Sep 17 '22 20:09

Energy