473,394 Members | 1,951 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,394 software developers and data experts.

Manipulating combo boxes in Vb.net

Hi,
I found a way to include my items dynamically by following this how-to:
http://www.mgbrown.com/PermaLink37.aspx

If you dont want to take a look on the link here it goes:

Expand|Select|Wrap|Line Numbers
  1. Public Class ValueDescriptionPair
  2.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  3.    'Class used to control the comboBox components
  4.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  5.    'Usage:
  6.    'To add items to the list you use code like this:
  7.    '  
  8.    'ComboBox1.Items.Add(New ValueDescriptionPair(1, "first item"))
  9.    'ComboBox1.Items.Add(New ValueDescriptionPair(2, "second item"))
  10.    'ComboBox1.Items.Add(New ValueDescriptionPair(3, "third item"))
  11.    '
  12.    'To get the value stored in Value and displays in a message box:
  13.    'Dim ItemSelected As Integer
  14.    'ItemSelected = CType(ComboBox1.SelectedItem,ValueDescriptionPair).Value
  15.    'MsgBox("Value Selected = " & ItemSelected)
  16.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  17.  
  18.    Private m_Value As Object
  19.    Private m_Description As String
  20.  
  21. #Region "properties"
  22.  
  23.    Public ReadOnly Property Value() As Object
  24.       Get
  25.          Return m_Value
  26.       End Get
  27.    End Property
  28.    Public ReadOnly Property Description() As String
  29.       Get
  30.          Return m_Description
  31.       End Get
  32.    End Property
  33.  
  34. #End Region
  35.  
  36.    Public Sub New(ByVal NewValue As Object, ByVal NewDescription As String)
  37.       m_Value = NewValue
  38.       m_Description = NewDescription
  39.    End Sub
  40.  
  41.    Public Overrides Function ToString() As String
  42.       Return m_Description
  43.    End Function
  44.  
  45. End Class
  46.  
But, what if you want to change the selected property to an ValueDescriptionPair added value?

For example, I did:

Expand|Select|Wrap|Line Numbers
  1. CmbBoxType.Items.Add(New ValueDescriptionPair(1, "Type 1")) 
  2. CmbBoxType.Items.Add(New ValueDescriptionPair(2, "Type 2")) 
on form load.. and then to set the selected value to the second option the .SelectedItem property receives what?
How would you know the reference to your ValueDescriptionPair like this?

thanks
Sep 19 '07 #1
1 2711
Just found a solution, dont know if the best but I simply store a reference of all ValueDescriptionPair in an array. Like this:

Private TypesArray(TypesAvailable - 1) As ValueDescriptionPair

Expand|Select|Wrap|Line Numbers
  1. TypesArray(0) = New ValueDescriptionPair(1, "Type 1")
  2. TypesArray(1) = New ValueDescriptionPair(2, "Type 2")
  3. For i As Integer = 0 To TypesArray.Length - 1
  4.          CmbBoxType.Items.Add(TypesArray(i))
  5. Next
then I can say:

Expand|Select|Wrap|Line Numbers
  1. CmbBoxType.SelectedItem = ConnTypesArray(0)
hope this helps someone with similar problem
Sep 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: FZ | last post by:
Hi Gang, I was wondering if a generous person might be able to walk me through what I believe is a pretty simple task. I actually have significant Access experience, but I haven't done it in...
0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
2
by: someshbakliwal | last post by:
Hi, I have created some autopopulating combo boxes on my HTML page (script- Javascript). so these combo boxes are autopopulated with choices made in previous combo boxes. The problem I am facing is...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.