We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,820 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

add items to combobox

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...

8
Contributors
11
Replies
4 Years
Discussion Span
11 Months Ago
Last Updated
52
Views
Question
Answered
_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
Jx_Man
Senior Poster
3,526 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 515
Skill Endorsements: 64

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..

_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

open connection is required to connect.

Jx_Man
Senior Poster
3,526 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 515
Skill Endorsements: 64

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...

_::suhanna::_
Newbie Poster
24 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Years Ago by Jx_Man

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

MukeshJod
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

ravindraravi
Newbie Poster
2 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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)
Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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..???

Havatra
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
Havatra
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

pradeepshine1
Newbie Poster
1 post since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1444 seconds using 2.67MB