Solved

Adding first blank row to combobox

Posted on 2010-08-22
7
889 Views
Last Modified: 2012-06-27
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();
            }
        }
0
Comment
Question by:GRChandrashekar
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:nipunu
ID: 33498521
<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
0
 

Author Comment

by:GRChandrashekar
ID: 33498554
Sorry This is winforms
0
 
LVL 6

Expert Comment

by:nipunu
ID: 33498658
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.



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:GRChandrashekar
ID: 33498713
Can I have code example to match my code ?
0
 

Author Comment

by:GRChandrashekar
ID: 33498856
Can I have code example to match my code ?
0
 
LVL 10

Accepted Solution

by:
joriszwaenepoel earned 500 total points
ID: 33499063
You can insert a new object into the "datasourcemenusubgroup" collection (at index 0) with an ID that you can recognize, and an empty description.

var emptyItem = New Xxxxx();
emptyItem.MENUSUBGROUPID = "0"
emptyItem.DECRIPTION = string.Empty;
datasourcemenusubgroup.Insert(0, emptyItem);
cmbmenusubgroupid.DataSource = datasourcemenusubgroup;
0
 

Author Comment

by:GRChandrashekar
ID: 33499103
Not getting first line

 var emptyItem = new myitem();

"myitem" cannot resolve symbol
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Long URL in SMS 6 32
Performance  Html.BeginForm vs jQuery 3 45
Not showing page correctly 3 29
SQL Exceptions 3 35
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now