473,320 Members | 2,094 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,320 software developers and data experts.

copying combos

hi all

i should copy the items of a combo to n other combos.

it's not a cycle:
With cboColor1
.Items.Add("ffffff")
.Items.Add("cecece")
...
.SelectedIndex = 0
End With
and the list may be long enough.

is there a quick way to replicate the content of combo1 to others without
copying its code?

tia, z.

Jan 5 '08 #1
11 1292
On Jan 5, 10:07 pm, "Zebra Code" <ZebraCode2...@gmail.comwrote:
hi all

i should copy the items of a combo to n other combos.

it's not a cycle:
With cboColor1
.Items.Add("ffffff")
.Items.Add("cecece")
...
.SelectedIndex = 0
End With
and the list may be long enough.

is there a quick way to replicate the content of combo1 to others without
copying its code?

tia, z.
Just right click combo control which is placed on your form, then
right click on it "copy" then "paste" into another form you desire.

Hope this helps.
Jan 5 '08 #2

"kimiraikkonen" <ki*************@gmail.comkirjoitti viestissä
news:ee**********************************@i12g2000 prf.googlegroups.com...
>
Just right click combo control which is placed on your form, then
right click on it "copy" then "paste" into another form you desire.

Hope this helps.
This can be done only is design mode and I don't think that this was the
original problem.

You might declare a function or sub that adds items to combos.

Public Sub AddItems (ByRef source as ComboBox)

' Combos where to copy items from source
Dim Combos() as ComboBox={combo2, combo3, ... }

For Each Combo as ComboBox In Combos
For Each Item as Object in source.Items

Combo.Items.Add(Item)

Next
Next

End Sub
-Teemu

Jan 5 '08 #3
On Sat, 5 Jan 2008 21:07:33 +0100, "Zebra Code"
<Ze***********@gmail.comwrote:
>hi all

i should copy the items of a combo to n other combos.

it's not a cycle:
With cboColor1
.Items.Add("ffffff")
.Items.Add("cecece")
...
.SelectedIndex = 0
End With
and the list may be long enough.

is there a quick way to replicate the content of combo1 to others without
copying its code?

tia, z.
Untested code:

Private Sub CopyCombo(src as ComboBox, dest as ComboBox)

dest.Items.Clear()
For indx As Integer = 0 To src.Items.Count - 1
dest.Items.Add(src.Items.Item(indx).ToString())
Next
desc.SelectedIndex = 0

End Sub

Another approach that I like better is to create an ArrayList with the
items in it, and then build a Sub that populates a ComboBox from an
ArrayList.

Or create an ArrayList and use it as the DataSource for all of the
comboboxes. Just be sure to use a new currency manager for each
combobox, otherwise when you change one all will change.
Jan 5 '08 #4

"Teemu" <ts*****@hotmail.com>
"kimiraikkonen" <ki*************@gmail.com>
>Just right click combo control which is placed on your form, then
right click on it "copy" then "paste" into another form you desire.
Hope this helps.

This can be done only is design mode and I don't think that this was the
original problem.
that's right. at designtime the combo is just empty. it gets loaded at
runtime. meantime by code, in future maybe by means of a textfile.
You might declare a function or sub that adds items to combos.
Public Sub AddItems (ByRef source as ComboBox)
' Combos where to copy items from source
Dim Combos() as ComboBox={combo2, combo3, ... }
For Each Combo as ComboBox In Combos
For Each Item as Object in source.Items
Combo.Items.Add(Item)
Next
Next
End Sub
i'm going to test it. it sounds just perfect.
thanks so much
ciao, z.

Jan 5 '08 #5

"Jack Jackson"
Untested code:

Private Sub CopyCombo(src as ComboBox, dest as ComboBox)

dest.Items.Clear()
For indx As Integer = 0 To src.Items.Count - 1
dest.Items.Add(src.Items.Item(indx).ToString())
Next
desc.SelectedIndex = 0

End Sub

Another approach that I like better is to create an ArrayList with the
items in it, and then build a Sub that populates a ComboBox from an
ArrayList.

Or create an ArrayList and use it as the DataSource for all of the
comboboxes. Just be sure to use a new currency manager for each
combobox, otherwise when you change one all will change.
thank you, really. i'm gonna check it.
ciao, z.
Jan 5 '08 #6
On Jan 5, 11:36 pm, "Zebra Code" <ZebraCode2...@gmail.comwrote:
"Teemu" <tsir...@hotmail.com>
"kimiraikkonen" <kimiraikkone...@gmail.com>
Just right click combo control which is placed on your form, then
right click on it "copy" then "paste" into another form you desire.
Hope this helps.
This can be done only is design mode and I don't think that this was the
original problem.

that's right. at designtime the combo is just empty. it gets loaded at
runtime. meantime by code, in future maybe by means of a textfile.
Yes, but if you run your project you will get same items on runtime
and also you can modify combobox in designer with whole properties of
your combobox clone.
Jan 5 '08 #7

"kimiraikkonen"
>that's right. at designtime the combo is just empty. it gets loaded at
runtime. meantime by code, in future maybe by means of a textfile.

Yes, but if you run your project you will get same items on runtime
and also you can modify combobox in designer with whole properties of
your combobox clone.
ok, thanks. i'm newby with vbnet and was hoping there ws a straight clone
method. i'll search for it.
ciao, ZC

Jan 5 '08 #8
Taking Jack's code a little bit else

\\\
dest.Items.Clear()
For Each srcItem As String In src.Items
dest.Items.Add(srcItem)
Next
///
While in version 2008 this goes like this too (strongly typed).
\\\
dest.Items.Clear()
For Each srcItem In src.Items
dest.Items.Add(srcItem)
Next
///

There is nothing wrong with the code from Jack by the way, just to show how
nice version 2008 is in this.

Cor
"Zebra Code" <Ze***********@gmail.comschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
hi all

i should copy the items of a combo to n other combos.

it's not a cycle:
With cboColor1
.Items.Add("ffffff")
.Items.Add("cecece")
...
.SelectedIndex = 0
End With
and the list may be long enough.

is there a quick way to replicate the content of combo1 to others without
copying its code?

tia, z.
Jan 6 '08 #9

"Cor Ligthert[MVP]"
Taking Jack's code a little bit else

\\\
dest.Items.Clear()
For Each srcItem As String In src.Items
dest.Items.Add(srcItem)
Next
///
While in version 2008 this goes like this too (strongly typed).
\\\
dest.Items.Clear()
For Each srcItem In src.Items
dest.Items.Add(srcItem)
Next
///

There is nothing wrong with the code from Jack by the way, just to show
how nice version 2008 is in this.

Cor
this group is a mine.
thank you.
ciao, ZC

Jan 6 '08 #10

"kimiraikkonen" <ki*************@gmail.comkirjoitti viestissä
news:34**********************************@t1g2000p ra.googlegroups.com...
On Jan 5, 11:36 pm, "Zebra Code" <ZebraCode2...@gmail.comwrote:
>"Teemu" <tsir...@hotmail.com>
"kimiraikkonen" <kimiraikkone...@gmail.com>
Just right click combo control which is placed on your form, then
right click on it "copy" then "paste" into another form you desire.
Hope this helps.
This can be done only is design mode and I don't think that this was
the
original problem.

that's right. at designtime the combo is just empty. it gets loaded at
runtime. meantime by code, in future maybe by means of a textfile.

Yes, but if you run your project you will get same items on runtime
and also you can modify combobox in designer with whole properties of
your combobox clone.
But this works only if items can be added in design mode and I think that
this can't be done in this case.

And besides if you copy and paste a control in design mode you'll get two
controls which have same properties at that time. But those two controls
aren't linked so if you change properties it'll affect only one control not
both. Also if you add an item to combobox when program is running it will be
added only to one combobox not to both.

-Teemu

Jan 6 '08 #11
just to tel that i tried another way, using an array of combos.
there's thing to tune and i dont know yet ho to set the font (i'm a newby
here), but it seems to work.

thank you all
ZC

Public Class Form1

Dim cboColor() As ComboBox, txtValue() As TextBox, txtLabel() As TextBox
Dim nValues As Integer ' how many arrayed controls are actually on the
form

....

Private Sub cboValues_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboValues.SelectedIndexChanged
Dim j As Integer
If nValues 0 Then ' 1<nvalues<5, but for frm_load (nvalues=0)
For j = nValues To 0 Step -1
Me.Controls.Remove(cboColor(j))
Next
End If
nValues = CInt(cboValues.Text) - 1
Dim maxVal As Integer = CInt(cboValues.Text) - 1
For j = 0 To maxVal
' colors
ReDim Preserve cboColor(j)
cboColor(j) = New ComboBox
With cboColor(j)
.DropDownStyle = ComboBoxStyle.DropDownList
'.Font = system.Drawing.Font "Courier New"
.Top = lblCboColor.Top
.Left = lblCboColor.Left + lblCboColor.Width + (j * 90) + (j
* 5)
.Width = 90
.Items.Add("ffffff :: white")
...
.Items.Add("000000 :: black")
.SelectedIndex = j
End With
Me.Controls.Add(cboColor(j))

Jan 10 '08 #12

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

Similar topics

1
by: Keith | last post by:
A2003, Xp Pro. I've designed a form which contains 6 of combos. Three on the left are set up to select fields from a query, three on the right are set up to select values from the corresponding...
0
by: Eric Eggermann | last post by:
Hello, I'm rather a fan of creating classes derived from a combo box with one specific functionality like listing installed printers and whatnot. I call the code to load the combos from the...
3
by: BrianDH | last post by:
Hi I have a form with multi-tabs, and on each tab I have a one combo that has the same values. I populate all 3 combo with the same one datacall/dataset My problem is: when I make a value...
1
by: G .Net | last post by:
Hi I have a DataGrid which has combos in the first field. These combos are populated via a DataView from another table. When I click the header of the field i.e. to sort it, the rows are sorted...
4
by: Jack | last post by:
There used to be a classes and member functions combos on top of the code window (like vb6) Now they are all .cpp listed with the code window underneath it. Where can I find back the old combo...
2
by: Gordowey | last post by:
Hi all,...I have an special situation, that I can not solve.... I need some help This is my scenario: 1.- I have n-combos (showing available rooms from an hotel) in my web-page. The number of...
3
by: sberry | last post by:
I have three arrays... for instance $a = array('big', 'small', 'medium'); $b = array('old', 'new'); $c = array('blue', 'green'); I want to take those and end up with all of the combinations...
3
by: ilikebirds | last post by:
I am looking for a way to have one combo lookup drop down to autopopulate with multiple items based off another combo lookup. I've tried Me!rc1 = DLookup("", "", "Reject_Reason_1='" &...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.