CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Nov 2008
    Posts
    27

    Lightbulb Adding ComboBox Values At Run Time

    how to add values in combobox at run time in VB.NET????

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: hey anyone help me out plz

    Welcome to the forums

    Simply use :
    Code:
    YourComboBoxName.Items.Add("Whatever Value(s)")
    You could also use the Insert method, to add an item at a specific place ( index ) in the Combo.

  3. #3
    Join Date
    Nov 2008
    Posts
    27

    Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    Welcome to the forums

    Simply use :
    Code:
    YourComboBoxName.Items.Add("Whatever Value(s)")
    You could also use the Insert method, to add an item at a specific place ( index ) in the Combo.

    sir actually i want to add items in combobx at run time..when i run my form..Through your code il be only able to get fixed values which i have added in the code

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: hey anyone help me out plz

    Do you mean you have dynamic values ( for example an array ) that you want to add to the combobox ¿
    Can you please explain more on what values you want to add, what you want to do ¿

    It would still be using the same principal as this code in any case.

  5. #5
    Join Date
    Nov 2008
    Posts
    27

    Re: Adding ComboBox Values At Run Time

    yes i have dynamic values the user would be entering them at run time.i want to add departement names through the combobox.i had previosly added values using display value and display member but every time i had to debug in order to show the newly added item in the combobx

  6. #6
    Join Date
    Nov 2008
    Posts
    27

    Angry Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    Do you mean you have dynamic values ( for example an array ) that you want to add to the combobox ¿
    Can you please explain more on what values you want to add, what you want to do ¿

    It would still be using the same principal as this code in any case.
    yes i have dynamic values the user would be entering them at run time.i want to add departement names through the combobox.i had previosly added values using display value and display member but every time i had to debug in order to show the newly added item in the combobx

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: hey anyone help me out plz

    I don't understand this situation you are sitting with kriti

    This code is quite simple, why was there a need to debug ¿
    What precise code did you use ¿

    Let me see. the user types in a department name inside a Textbox, during run time - is that correct ¿
    If it was indeed entered into a textbox, you could perhaps use the textBox's Leave / LostFocus event, to add the entered item into the combobox.
    Let us presume your textBox is named txtDeptName and your combobox is named cbodeptname
    All you need to do ( in the Leave / LostFocus event of txtDeptName is :
    Code:
    cboDeptName.Items.Add(txtDeptName.Text)

  8. #8
    Join Date
    Nov 2008
    Posts
    27

    Question Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    I don't understand this situation you are sitting with kriti

    This code is quite simple, why was there a need to debug ¿
    What precise code did you use ¿

    Let me see. the user types in a department name inside a Textbox, during run time - is that correct ¿
    If it was indeed entered into a textbox, you could perhaps use the textBox's Leave / LostFocus event, to add the entered item into the combobox.
    Let us presume your textBox is named txtDeptName and your combobox is named cbodeptname
    All you need to do ( in the Leave / LostFocus event of txtDeptName is :
    Code:
    cboDeptName.Items.Add(txtDeptName.Text)
    yes the user enters through the text box and the same value is getting stored in the combobox ..but when i again run the program the combobox is not showing the values entered previously

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: hey anyone help me out plz

    Quote Originally Posted by kriti View Post
    but when i again run the program the combobox is not showing the values entered previously
    Does this mean you are exiting the program / unloading the form ¿
    So, are you looking for a way to permanently store the department names entered, and read from that list.

    Is this application using a database or something ¿

  10. #10
    Join Date
    Nov 2008
    Posts
    27

    Unhappy Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    I don't understand this situation you are sitting with kriti

    This code is quite simple, why was there a need to debug ¿
    What precise code did you use ¿

    Let me see. the user types in a department name inside a Textbox, during run time - is that correct ¿
    If it was indeed entered into a textbox, you could perhaps use the textBox's Leave / LostFocus event, to add the entered item into the combobox.
    Let us presume your textBox is named txtDeptName and your combobox is named cbodeptname
    All you need to do ( in the Leave / LostFocus event of txtDeptName is :
    Code:
    cboDeptName.Items.Add(txtDeptName.Text)
    sir plz reply>>>>

  11. #11
    Join Date
    Nov 2008
    Posts
    27

    Question Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    Does this mean you are exiting the program / unloading the form ¿
    So, are you looking for a way to permanently store the department names entered, and read from that list.

    Is this application using a database or something ¿
    yes sir i want to see the dept names in the combobox which are entered through the textbox permanetly every time i unload the form.do reply with the solution.

  12. #12
    Join Date
    Nov 2008
    Posts
    27

    Re: hey anyone help me out plz

    Quote Originally Posted by kriti View Post
    yes sir i want to see the dept names in the combobox which are entered through the textbox permanetly every time i unload the form.do reply with the solution.
    yes iam using the database

  13. #13
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: hey anyone help me out plz

    Thanx for finally telling us that you are using a database. If this was said in your first post, we'd have made much more progress by now.

    Are the connections set up, have you connected any of the controls to their appropriate fields, from the database, or haven't you connected anything yet ¿
    have you any knowledge of ADO.NET ¿

  14. #14
    Join Date
    Nov 2008
    Posts
    27

    Re: hey anyone help me out plz

    Quote Originally Posted by HanneSThEGreaT View Post
    Thanx for finally telling us that you are using a database. If this was said in your first post, we'd have made much more progress by now.

    Are the connections set up, have you connected any of the controls to their appropriate fields, from the database, or haven't you connected anything yet ¿
    have you any knowledge of ADO.NET ¿
    iam sorry new to everything...yes all my connectins with the database are made.just want this functionality...iam able to save the values entered in the textbox in the database.

  15. #15
    Join Date
    Nov 2008
    Posts
    27

    Re: hey anyone help me out plz

    Quote Originally Posted by kriti View Post
    iam sorry new to everything...yes all my connectins with the database are made.just want this functionality...iam able to save the values entered in the textbox in the database.
    yes iam familiar with ADO.NET

Page 1 of 2 12 LastLast

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

Featured