Results 1 to 2 of 2

Thread: Drop Down / Dataset , insert blank in top ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    24

    Drop Down / Dataset , insert blank in top ?

    I would like to inset blank or "select" in the top the dropdown,

    cbxStoreCategory.DataSource = categoriesBindingSource2;
    cbxStoreCategory.DisplayMember = "CategoryCode";

    //cbxStoreCategory.Items.Insert(0, "--Select--");

    however I cannot do this way, any suggestion ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Drop Down / Dataset , insert blank in top ?

    If you set the DataSource of a control then that control is bound to that data. It will display the data it is bound to and only the data it is bound to. If you want it to display a blank entry then you would have to add a blank entry to the data source. It is generally incorrect to do so though. Adding a blank entry implies that there is an entry that is blank that the user can select. That is not the same thing as them selecting no entry at all. If you want to clear the selection of a bound combo box then you need to set the SelectedIndex to -1, which equates to no selection. If you need to allow the user to do this themselves then I usually handle the KeyDown event and test for the Delete key and/or provide a right-click menu with a Clear option.

    Also, you should use the term "ComboBox" and not "dropdown". There is a similar control called "DropDownList" in ASP.NET so if you don't use the correct name then it may not be clear that you aren't creating a Web app with a DropDownList. Terminology is important.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width