By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

How to fill one ComboBox from other ComboBox control?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.