?
Solved

Adding first blank row to combobox

Posted on 2010-08-22
7
Medium Priority
?
895 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

718 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