Solved

Adding first blank row to combobox

Posted on 2010-08-22
7
888 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Aspnet xml 2 36
Problem to event 3 49
Chat Room 1 25
Parallel.ForEach using SendMailAsync() detect when loop is complete 24 29
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

13 Experts available now in Live!

Get 1:1 Help Now