Link to home
Start Free TrialLog in
Avatar of GRChandrashekar
GRChandrashekarFlag for India

asked on

Adding first blank row to combobox

Hi
I am populating the combobox with following code. I would like to ADD AND display a blank row as first row while loading the combobox and want to get rid of -1.
 private void Fillcmbmenusubgroupid()
        {
            try
            {
               

                bucketmenusubgroup.PredicateExpression.Add(MenusubgroupFields.Flag ==
                                                           StandardFlag.recordvalidflag);
                adaptermenusubgroup.FetchEntityCollection(datasourcemenusubgroup, bucketmenusubgroup,
                                                          0,
                                                          new SortExpression(
                                                              MenusubgroupFields.Description |
                                                              SortOperator.Ascending));

                cmbmenusubgroupid.DataSource = datasourcemenusubgroup;
                cmbmenusubgroupid.ValueMember = "MENUSUBGROUPID";
                cmbmenusubgroupid.DisplayMember = "DECRIPTION";
                cmbmenusubgroupid.SelectedIndex = -1;
               
               
            }
            catch (Exception ex)
            {
                GlobalErrorHandler.LogMessage(ex.StackTrace);
            }
            finally
            {
                adaptermenusubgroup.CloseConnection();
            }
        }
Avatar of nipunu
nipunu

<asp:DropDownList ID="DropDownListID" AppendDataBoundItems="true" runat="server">
     <asp:ListItem Text="Default text" Value="Default value" />
</asp:DropDownList>

Append data bound items  = true make sure that it will not remove your default item
Avatar of GRChandrashekar

ASKER

Sorry This is winforms
Try Create a object of ListItem specify value and text and then set the selected property of the listitem object to true and add listItem object to dropdownlist items collection. If the default that you want to set is already in your dropdown list then you can iterate over dropdownlist Items collection and set the selected property of the desired item in the collection.



Can I have code example to match my code ?
Can I have code example to match my code ?
ASKER CERTIFIED SOLUTION
Avatar of joriszwaenepoel
joriszwaenepoel
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not getting first line

 var emptyItem = new myitem();

"myitem" cannot resolve symbol