Results 1 to 3 of 3

Thread: [RESOLVED] Adding data to databinded Combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    Resolved [RESOLVED] Adding data to databinded Combobox

    Hai

    i am using combobox in winforms with c#.


    i have binded control with a Datatable

    cboEmpName.DisplayMember = "FULLNAME";
    cboEmpName.ValueMember = "EMPLOYEEID";

    and binded to datasource

    cboEmpName.DataSource = tblEMPLOYEE;


    now i should have a first member of Combobox as "----select----"

    i am trying to

    cboEmpName.Items.Insert("test",0);


    but it is getting error if i am trying this

    i am getting an error

    "Items collection cannot be modified when the DataSource property is set."


    Please help me in resolving this issue


    Thanks and Regards
    VInay Kumar

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

    Re: Adding data to databinded Combobox

    Exactly as the error message says. If a ComboBox is bound to a DataSource then it displays the contents of that DataSource. If you want to change what the ComboBox displays then you have to change the DataSource.

    Also, there's no need to put instructions in a ComboBox. People know that you select an item in a ComboBox. That is unnecessary UI clutter.
    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

  3. #3
    New Member
    Join Date
    Jan 2007
    Posts
    2

    Re: Adding data to databinded Combobox

    try it....may help u

    after databind occured..
    cboEmpName.Items.Insert(0,"--Select--");

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