| | |
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:
Solved Threads: 2
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.
Thanks!
VB.NET Syntax (Toggle Plain Text)
verticalBarComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}) backSlashComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}) colonComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}) quoteComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
Thanks!
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
As RamyMahrous said use an array. If you deceide to add or remove anything later you only need to do it in one place.
VB.NET Syntax (Toggle Plain Text)
Dim ary As String() = {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"} Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load verticalBarComboBox.Items.AddRange(ary) backSlashComboBox.Items.AddRange(ary) colonComboBox.Items.AddRange(ary) quoteComboBox.Items.AddRange(ary) End Sub
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Does this leak memory?
- Next Thread: Save password...plz help
| Thread Tools | Search this Thread |
.net .net2008 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms generatetags gridview html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey table temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year






