Results 1 to 2 of 2

Thread: add a new row in a combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    88

    add a new row in a combobox

    this my code to populate a combobox
    Code:
    Dim myCmd1 As SqlClient.SqlCommand = cn.CreateCommand
            myCmd1.CommandText = "Select emp_name from emp_info"
            myCmd1.Connection = cn
            Dim da As New SqlClient.SqlDataAdapter()
            da.SelectCommand = myCmd1
            Dim dt As New DataTable()
            da.Fill(dt)
    
    
            Me.ComboBox1.DisplayMember = "emp_name"
            Me.ComboBox1.ValueMember = "emp_name"
            Me.ComboBox1.DataSource = dt
    i want to add a new row above all emp names.."ALL"..
    how do i do that??/
    thanks

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

    Re: add a new row in a combobox

    This question has been asked and answered many times. You cannot add items to a bound ComboBox. If a ComboBox is bound ten it shows the contents of its DataSource, period. If you want to add items then you have to add them to the DataSource; in your case the DataTable.
    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