Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Item collection cannot be modified when datasource property is set

Item collection cannot be modified when datasource property is set

Scheduled Pinned Locked Moved C#
databasehelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahul DSG
    wrote on last edited by
    #1

    Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks

    H M 3 Replies Last reply
    0
    • R Rahul DSG

      Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks

      H Offline
      H Offline
      himanshu2561
      wrote on last edited by
      #2

      when it is giving error? At the time of binding or at cother point. post code where it gives the error

      himanshu

      1 Reply Last reply
      0
      • R Rahul DSG

        Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks

        M Offline
        M Offline
        Morteza Karimian Kelishadrokhi
        wrote on last edited by
        #3

        so, you can refared to below link: Add Item to Binded Combo Box[^] i founded my answer in this link

        1 Reply Last reply
        0
        • R Rahul DSG

          Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks

          M Offline
          M Offline
          Morteza Karimian Kelishadrokhi
          wrote on last edited by
          #4

          i sent full article of this code to CODEPROJECT . after that my article being accepted, you can use of them. but code is like this: you must use of NORTHWINFD Database

          private void button1_Click(object sender, EventArgs e)
          {
          SqlConnection co = new SqlConnection();
          co.ConnectionString = @"Server=.\SQLEXPRESS;initial catalog='NORTHWND.MDF';Trusted_Connection=Yes";
          SqlCommand cmdSelect = new SqlCommand();
          cmdSelect.Connection = co;
          cmdSelect.CommandText = "SELECT (FirstName+' '+LastName) AS Fullname FROM Employees";
          SqlDataAdapter da = new SqlDataAdapter(cmdSelect);
          DataTable dt = new DataTable();
          co.Open();
          da.Fill(dt);
          comboBox1.DataSource = null;
          comboBox1.DataSource = dt;
          comboBox1.ValueMember = "Fullname";
          co.Close();
          }
          private void button2_Click(object sender, EventArgs e)
          {
          DataTable dt = (DataTable)comboBox1.DataSource;
          DataRow dr = dt.NewRow();
          dr[0] = "< select item >";
          dt.Rows.InsertAt(dr, 0);
          comboBox1.DataSource = dt;

                  comboBox1.SelectedIndex = 0;
              }
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups