473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to fill one ComboBox from other ComboBox control?

Hi All,

How to fill one ComboBox from other ComboBox control?

1) Only setting the reference does the trick but doesn't show items in
control. If you see in immediate window, it shows the item count correctly
in destination ComboBox control.

Me.ComboBox1 = objFrmMain.ComboBox1

Or

2)should I loop through the Items collection of source ComboBox control and
add destination control item?

For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1

Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)

Loop

Any help will be appreciated.

Thanks and Regards

Sakharam Phapale
Nov 21 '05 #1
6 7786
Sakharam,

The first question is, are you using a datasource or are you filling the
items with objects?

After that answer from you, the answer to you is easy.

Cor

"Sakharam Phapale"> Hi All,

How to fill one ComboBox from other ComboBox control?

1) Only setting the reference does the trick but doesn't show items in
control. If you see in immediate window, it shows the item count correctly
in destination ComboBox control.

Me.ComboBox1 = objFrmMain.ComboBox1

Or

2)should I loop through the Items collection of source ComboBox control
and
add destination control item?

For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1

Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)

Loop

Any help will be appreciated.

Thanks and Regards

Sakharam Phapale

Nov 21 '05 #2
Hi Cor,

MainForm is MDI form and cmbSelectUser is member control of it.
I am filling it as follow.

Class MainForm

Public WithEvents cmbSelectUser as ComboBox

Private Sub FillUserComboBox()
Dim SmapiApp As New smapiApplication()
Dim SmapiUser As smapiUser
For Each SmapiUser In SmapiApp.smapiUsers
cmbSelectUser.Items.Add(SmapiUser.Name)
Next
End Sub

End Class

-----

I don't want to use above code again in child forms.
Same elements should be copied in cmbUser2 of child form.

Class ChildForm

Public WithEvents cmbUser2 as ComboBox
Private Sub FillUser()

' I want to write code here...
End Sub

End Class

Thanks and Regards
Sakharam Phapale
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Sakharam,

The first question is, are you using a datasource or are you filling the
items with objects?

After that answer from you, the answer to you is easy.

Cor

"Sakharam Phapale"> Hi All,

How to fill one ComboBox from other ComboBox control?

1) Only setting the reference does the trick but doesn't show items in
control. If you see in immediate window, it shows the item count correctly in destination ComboBox control.

Me.ComboBox1 = objFrmMain.ComboBox1

Or

2)should I loop through the Items collection of source ComboBox control
and
add destination control item?

For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1

Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)

Loop

Any help will be appreciated.

Thanks and Regards

Sakharam Phapale


Nov 21 '05 #3
Sakharam,

Have a look for this for that.

Dim myarray(ComboBox1.Items.Count - 1) As Object
ComboBox1.Items.CopyTo(myarray, 0)
ComboBox2.Items.AddRange(myarray)

Here I use the collection from the combobox1, however probably you can use
directly those smapiUsers in both comboboxes when you CopyTo them first to a
one dimensional array.

I hope this helps?

Cor
"Sakharam Phapale" <sp******@annetsite.com>
Hi Cor,

MainForm is MDI form and cmbSelectUser is member control of it.
I am filling it as follow.

Class MainForm

Public WithEvents cmbSelectUser as ComboBox

Private Sub FillUserComboBox()
Dim SmapiApp As New smapiApplication()
Dim SmapiUser As smapiUser
For Each SmapiUser In SmapiApp.smapiUsers
cmbSelectUser.Items.Add(SmapiUser.Name)
Next
End Sub

End Class

-----

I don't want to use above code again in child forms.
Same elements should be copied in cmbUser2 of child form.

Class ChildForm

Public WithEvents cmbUser2 as ComboBox
Private Sub FillUser()

' I want to write code here...
End Sub

End Class

Thanks and Regards
Sakharam Phapale
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Sakharam,

The first question is, are you using a datasource or are you filling the
items with objects?

After that answer from you, the answer to you is easy.

Cor

"Sakharam Phapale"> Hi All,
>
>
>
> How to fill one ComboBox from other ComboBox control?
>
>
>
> 1) Only setting the reference does the trick but doesn't show items in
> control. If you see in immediate window, it shows the item count correctly > in destination ComboBox control.
>
>
>
> Me.ComboBox1 = objFrmMain.ComboBox1
>
>
>
> Or
>
>
>
> 2)should I loop through the Items collection of source ComboBox control
> and
> add destination control item?
>
>
>
> For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1
>
> Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)
>
> Loop
>
>
>
>
>
> Any help will be appreciated.
>
>
>
> Thanks and Regards
>
> Sakharam Phapale
>
>



Nov 21 '05 #4
Thanks Cor,

But one more question.
If I use statement as follows

Me.cmbUser2 = objMainForm.cmbselectUser

I don't see any item in ComboBox.
But, If I query in Immediate window as
?cmbUser2.Items.Count
It gives me 10 which is correct.
Then why comboBox doesn't show any item when I try to dropdown it?

Regards,
Sakharam


"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Sakharam,

Have a look for this for that.

Dim myarray(ComboBox1.Items.Count - 1) As Object
ComboBox1.Items.CopyTo(myarray, 0)
ComboBox2.Items.AddRange(myarray)

Here I use the collection from the combobox1, however probably you can use
directly those smapiUsers in both comboboxes when you CopyTo them first to a one dimensional array.

I hope this helps?

Cor
"Sakharam Phapale" <sp******@annetsite.com>
Hi Cor,

MainForm is MDI form and cmbSelectUser is member control of it.
I am filling it as follow.

Class MainForm

Public WithEvents cmbSelectUser as ComboBox

Private Sub FillUserComboBox()
Dim SmapiApp As New smapiApplication()
Dim SmapiUser As smapiUser
For Each SmapiUser In SmapiApp.smapiUsers
cmbSelectUser.Items.Add(SmapiUser.Name)
Next
End Sub

End Class

-----

I don't want to use above code again in child forms.
Same elements should be copied in cmbUser2 of child form.

Class ChildForm

Public WithEvents cmbUser2 as ComboBox
Private Sub FillUser()

' I want to write code here...
End Sub

End Class

Thanks and Regards
Sakharam Phapale
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Sakharam,

The first question is, are you using a datasource or are you filling the items with objects?

After that answer from you, the answer to you is easy.

Cor

"Sakharam Phapale"> Hi All,
>
>
>
> How to fill one ComboBox from other ComboBox control?
>
>
>
> 1) Only setting the reference does the trick but doesn't show items in > control. If you see in immediate window, it shows the item count

correctly
> in destination ComboBox control.
>
>
>
> Me.ComboBox1 = objFrmMain.ComboBox1
>
>
>
> Or
>
>
>
> 2)should I loop through the Items collection of source ComboBox control > and
> add destination control item?
>
>
>
> For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1
>
> Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)
>
> Loop
>
>
>
>
>
> Any help will be appreciated.
>
>
>
> Thanks and Regards
>
> Sakharam Phapale
>
>



Nov 21 '05 #5
Sakharam,

Me.cmbUser2 = objMainForm.cmbselectUser
With this statement are you telling to use for all code for cmbUser2 the
complete combobox on form1 with all its behaviour (events etc) on form1.

I do not know what is the effect. However I don't think that it will work as
you wish.

Cor
I don't see any item in ComboBox.
But, If I query in Immediate window as
?cmbUser2.Items.Count
It gives me 10 which is correct.
Then why comboBox doesn't show any item when I try to dropdown it?

Regards,
Sakharam


"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Sakharam,

Have a look for this for that.

Dim myarray(ComboBox1.Items.Count - 1) As Object
ComboBox1.Items.CopyTo(myarray, 0)
ComboBox2.Items.AddRange(myarray)

Here I use the collection from the combobox1, however probably you can
use
directly those smapiUsers in both comboboxes when you CopyTo them first
to

a
one dimensional array.

I hope this helps?

Cor
"Sakharam Phapale" <sp******@annetsite.com>
> Hi Cor,
>
> MainForm is MDI form and cmbSelectUser is member control of it.
> I am filling it as follow.
>
> Class MainForm
>
> Public WithEvents cmbSelectUser as ComboBox
>
> Private Sub FillUserComboBox()
> Dim SmapiApp As New smapiApplication()
> Dim SmapiUser As smapiUser
> For Each SmapiUser In SmapiApp.smapiUsers
> cmbSelectUser.Items.Add(SmapiUser.Name)
> Next
> End Sub
>
> End Class
>
> -----
>
> I don't want to use above code again in child forms.
> Same elements should be copied in cmbUser2 of child form.
>
> Class ChildForm
>
> Public WithEvents cmbUser2 as ComboBox
> Private Sub FillUser()
>
> ' I want to write code here...
> End Sub
>
> End Class
>
> Thanks and Regards
> Sakharam Phapale
>
>
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:Ox**************@TK2MSFTNGP10.phx.gbl...
>> Sakharam,
>>
>> The first question is, are you using a datasource or are you filling the >> items with objects?
>>
>> After that answer from you, the answer to you is easy.
>>
>> Cor
>>
>> "Sakharam Phapale"> Hi All,
>> >
>> >
>> >
>> > How to fill one ComboBox from other ComboBox control?
>> >
>> >
>> >
>> > 1) Only setting the reference does the trick but doesn't show items in >> > control. If you see in immediate window, it shows the item count
> correctly
>> > in destination ComboBox control.
>> >
>> >
>> >
>> > Me.ComboBox1 = objFrmMain.ComboBox1
>> >
>> >
>> >
>> > Or
>> >
>> >
>> >
>> > 2)should I loop through the Items collection of source ComboBox control >> > and
>> > add destination control item?
>> >
>> >
>> >
>> > For intCount = 0 to objFrmMain.ComboBox1.Items.Count-1
>> >
>> > Me.ComboBox1 = objFrmMain.ComboBox1.Items.Item(intCount)
>> >
>> > Loop
>> >
>> >
>> >
>> >
>> >
>> > Any help will be appreciated.
>> >
>> >
>> >
>> > Thanks and Regards
>> >
>> > Sakharam Phapale
>> >
>> >
>>
>>
>
>



Nov 21 '05 #6

"Sakharam Phapale" <sp******@annetsite.com> wrote

How to fill one ComboBox from other ComboBox control?
Try:
Me.ComboBox1.DataSource = objFrmMain.ComboBox1.Items

LFS
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pepehammer | last post by:
Hi everybody! I got a combobox to fill. I want to display some information (Text), but when I select a item, I want to return a number. The info I want to fill in is something like this: ...
3
by: Maurice Mertens | last post by:
Hi all, In VB.NET you can set the DropDownStyle for a combobox to 'DropDown' or 'DropDownList'. When you set it to DropDownList, it supports auto-fill. But when you set it to 'DropDown', the...
2
by: Joanne Lewis | last post by:
I am having a great deal of difficulty with a form. Basically, I would like to enter an account # and have the account #, patient first name, and patient last name automatically fill. The form...
4
by: marko | last post by:
Hello. I hope tht someone is going to be able tohelp me, so here is my problem. I have a main table with ID(primary Key),Brend,Model,Price. Then I have a sales table which is filled with a sales...
5
by: malcolm | last post by:
I'm trying to make a combo box custom control (Windows Forms .NET 1.1 c#) that can behave like a label programatically at run time. This is actually a strong feature request by our customers. I...
7
by: sparkle | last post by:
Hi Everybody, I'm filling a combobox from a class, which works fine on it's own. But when I insert code to fill in other controls something in the combobox fill is causing the...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
5
by: Tark Siala | last post by:
hi dear i'm programmer with VB6, but now i starting with C#. first problem is coming when i need fill "ComboBox Control", as you know when i fill combobox in VB6 by this code: comboX.AddItem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.