adding values in a combobox at run time

I want to add values(departement names) to a combobx at run time and t

Page 1 of 1

2 Replies - 3566 Views - Last Post: 17 November 2008 - 01:42 PM Rate Topic: -----

#1 kriti ohri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 08

adding values in a combobox at run time

Post icon  Posted 16 November 2008 - 11:00 PM

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Dim objcommand As New SqlCommand
        objcommand.Connection = objconnection
        'objconnection.Open()




        objcommand.CommandText = "Insert into dept_mas (dept_code,dept_name) values (@dept_code,@dept_name)"
        objcommand.Parameters.AddWithValue("@dept_code", cbodept.Text)
        'go_button.Enabled = True


        'objcommand.Parameters.AddWithValue("@dept_name", txtdeptname.Text)
        objcommand.Parameters.AddWithValue("@dept_name", Combdeptname.Text)
        'If txtdeptname.Text = "" Then
        If Combdeptname.Text = "" Then
            btnnew.Enabled = False
            Combdeptname.Enabled = True
            Combdeptname.Focus()
            MessageBox.Show("You must enter the departement name.", " Departement Name Entry Error", _
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Else

            Try
                Dim ans As MsgBoxResult
                ans = MsgBox("record Saved ", +MsgBoxStyle.Question, "Save confirmation")
                Button1.Focus()
                Combdeptname.Enabled = False
                objconnection.Open()
                objcommand.ExecuteNonQuery()
                enable_disabledeptmas(False)
                StatusStrip1.Items(0).Text = " Department Name Record Saved"
                btnnew.Enabled = True
                btnsave.Enabled = True

            Catch SqlExceptionErr As SqlException
                MessageBox.Show(SqlExceptionErr.Message)










            End Try
            objconnection.Close()
        End If

        If Combdeptname.Text = "" Then


            ErrorProvider1.SetError(Combdeptname, "Cannot leave textbox blank")
        Else
            ErrorProvider1.SetError(Combdeptname, "")


        End If
        'btnsave.Enabled = False
        Combdeptname.Enabled = True

        txtedit.Enabled = True

        btnupdate.Enabled = False

       






    End Sub



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: adding values in a combobox at run time

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: adding values in a combobox at run time

Posted 16 November 2008 - 11:05 PM

Hello and welcome to Dream.In.Code kriti ohri, I hope you enjoy your stay :)

For future reference you want to post your programming questions in the proper language forum, in this case the VB.NET forum. This particular forum is for introductions only and wont get seen by the many VB.NET experts we have.

Moved to VB.NET :)

EDIT:
Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 SimbaK2K  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-November 08

Re: adding values in a combobox at run time

Posted 17 November 2008 - 01:42 PM

Unless I'm reading the question wrong, can you not just change the collection data in the items property of the combo box? So when you load the program it'll add those to the combo box.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1