1,105,380 Community Members

add items to combobox

Member Avatar
_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi...

im working with vb.net
can u guys help me...

can u guys give me some sample code how to add item and display item using combo box?

please help me...

thanks...

Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 

needed a combobox to display,textbox for input and button.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ComboBox1.Items.Add(TextBox1.Text)
    End Sub
Member Avatar
_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hiii...thanks Jx_Man..

this is my code :

Private Sub AddArea_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        area = New AflexiArea
        AddRate()

    End Sub

    Sub AddRate()
        area = New AflexiArea
        ReadSqlData("select (id, value) from rate")
        While myReader.Read
            ComboBox1.Items.Add(myReader.GetValue(0))

            Exit While

        End While
        CloseSqlRead()
    End Sub

but when i run..this error msg will out...
"Execute reader required an open and available connection. The connection's current state is close"

it's someting wrong with my code?

thanks..

Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 

open connection is required to connect.

Member Avatar
_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hello..
thanks Jx_Man for ur concent helping me...

im already done now..

actually no need to put exit while

this is the real code:

Sub readrate()
        lot = New AflexiLotParking
        ReadSqlData("select value from rate")
        While myReader.Read
            ComboBox1.Items.Add("RM " & myReader.GetValue(0))

        End While
        CloseSqlRead()
    End Sub

thanks...

Question Answered as of 6 Years Ago by Jx_Man
Member Avatar
MukeshJod
Newbie Poster
1 post since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

unable to cast COM object ADODB.Recordset to class type System.data.dataset instances of types thatrepresent COM Components cannot to be Cast to typesthat do that repersent com Components however they can be cast to interfaces as long as the underlying COM Components Supports QueryInterface calls for the IID of the Interface

Member Avatar
ravindraravi
Newbie Poster
2 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

HI you can add item in combobox by a simple statement like:

ComboBox_name.Items.add("Item Name",index)

ComboBox_name:- any name given to Combobox
Item Name:- name of element to be added
index :- index to which its position.

Member Avatar
Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi frnds..
i have same query but i want to use Add Range Method to fill me combo box..
please guide

Member Avatar
Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

A thread is available for this Issue.
Here are both the ways to fill a combobox.
By Add() and Addrange()
By Add()

combobox1.Items.Add("Sunday")
        combobox1.Items.Add("Monday")
        combobox1.Items.Add("Tuesday")
        combobox1.Items.Add("Wednesday")
        combobox1.Items.Add("Thursday")
        combobox1.Items.Add("Friday")
        combobox1.Items.Add("Saturday")

By AddRange()

Dim days() As String = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
 ComboBox1.Items.AddRange(days)
Member Avatar
Havatra
Newbie Poster
2 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Well, it's many ways to do this apparently... But I wondered how it's possible to copy all the items from one ComboBox (for example in form1) to another ComboBox in form 2?
I write it something like this:

ComboBox1.Items.AddRange(New String() {Form2.ComboBox1.Items})

But I get an error like

"Value of type 'System.Windows.Forms.ComboBox.ObjectCollection' cannot be converted to 'String'.

How do I copy from one to another..???

Member Avatar
Havatra
Newbie Poster
2 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

You just have to insert this:

Dim indx As Double = -1
Do Until indx = 70
    indx += 1
    ComboBox1.Items.Insert(indx, Form1.ComboBox1.Items.Item(indx))
Loop
Member Avatar
pradeepshine1
Newbie Poster
1 post since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

we are updating branch master on given application, but when we populate combobox updated master not shown, can i call it's software bug or any thing else Please suggest.

Member Avatar
emirhan55553
Newbie Poster
2 posts since Jan 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, I vb.net Where do I get the ComboBox, and similar things?

Member Avatar
emirhan55553
Newbie Poster
2 posts since Jan 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
combobox1.Items.Add("Sunday")
        combobox1.Items.Add("Monday")
        combobox1.Items.Add("Tuesday")
        combobox1.Items.Add("Wednesday")
        combobox1.Items.Add("Thursday")
        combobox1.Items.Add("Friday")
        combobox1.Items.Add("Saturday")
lethalmarc
Newbie Poster
1 post since Feb 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 
    ComboBox1.Items.Add("Sunday")
    ComboBox1.Items.Add("Monday")
    ComboBox1.Items.Add("Tuesday")
    ComboBox1.Items.Add("wednesday")
    ComboBox1.Items.Add("Thursday")
    ComboBox1.Items.Add("Friday")
    ComboBox1.Items.Add("Saturday")

    ComboBox1.SelectedItem = ComboBox1.Items(3)

Above samples full source code ..VB.Net combobox

marc

sxairyl
Newbie Poster
1 post since Feb 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Hi everyone ..

can you please help me?

I want to add an item to a combobox from another form..
can you give me an example codes?

Thankyou in advance..

Member Avatar
Spyderbane
Newbie Poster
9 posts since Feb 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Sxairyl,
Maybe we should create a new post. This one looks very old.

Member Avatar
Spyderbane
Newbie Poster
9 posts since Feb 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

But try form2.combobox.items.add("Info")
Change form2 to what ever form the combobox is on.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article