Solved

Adding first blank row to combobox

Posted on 2010-08-22
7
890 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 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