How do I declare a single Object instance then reuse it in each ComboBox?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 27
Reputation: edgar5 is an unknown quantity at this point 
Solved Threads: 2
edgar5 edgar5 is offline Offline
Light Poster

How do I declare a single Object instance then reuse it in each ComboBox?

 
0
  #1
Dec 31st, 2008
All these New Object()s are identical (and in fact, much longer!) How do I declare a single instance then reuse it in each ComboBox .Items.AddRange()? I am using Visual Studio 2008/Visual Basic.

  1. verticalBarComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  2. backSlashComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  3. colonComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  4. quoteComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: How do I declare a single Object instance then reuse it in each ComboBox?

 
0
  #2
Jan 1st, 2009
declare simply array from object datatype then call AddRange for all combo boxes and pass this array!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: How do I declare a single Object instance then reuse it in each ComboBox?

 
0
  #3
Jan 1st, 2009
As RamyMahrous said use an array. If you deceide to add or remove anything later you only need to do it in one place.
  1. Dim ary As String() = {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}
  2.  
  3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. verticalBarComboBox.Items.AddRange(ary)
  5. backSlashComboBox.Items.AddRange(ary)
  6. colonComboBox.Items.AddRange(ary)
  7. quoteComboBox.Items.AddRange(ary)
  8. End Sub
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 27
Reputation: edgar5 is an unknown quantity at this point 
Solved Threads: 2
edgar5 edgar5 is offline Offline
Light Poster

Re: How do I declare a single Object instance then reuse it in each ComboBox?

 
0
  #4
Jan 1st, 2009
Thanks to both!

As this is my first VB project, I needed the code snippet.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC