Solved

Adding first blank row to combobox

Posted on 2010-08-22
7
893 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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