Solved

Add Specific Text with IDs to ComboBox

Posted on 2009-05-04
8
320 Views
Last Modified: 2012-05-06
I have a tabcontrol where each tabpages tag holds an id number and the text of the tabpage holds the name of the item.
ie.
TabPage 0
Text = Heat 1
Tag = 2

Text = Heat 2
Tag = 3

I now need to take the text and tag from each tab and load into a combobox.
Being a .Net newbi and since it's not coming from a datasource, I am not sure of the best way to fill this.

Please provide an example and not a link.  Clicking on links crashes my ie.
Thanks
0
Comment
Question by:Sheritlw
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301280
'Copy and paste this code in your form...

Private Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class


For Each ctrl As TabPage In TabControl1.TabPages

DIm MyItem as new MyItems

MyItem.text = Tabpage.Text
MyItem.Id =  ctype(Tabpage.tag,integer)

Combobox1.Item.Add(MyItem)
           
Next
0
 

Author Comment

by:Sheritlw
ID: 24301528
That works great, but since value member isn't used how do I get what item ID is selected?
Thanks
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301622
Try this one...

If not Combobox1.SelectedItem is nothing then
   msgbox(ctype(Combobox1.SelectedItem,MyItems).ID)
End If
0
 

Author Comment

by:Sheritlw
ID: 24301695
The comboboxes are on a dialog form that I fill from the main form.  The main form has the class code you gave me before.
How would I declare myitems in the dialog form, since it won't be new?
Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24301748
Okey Here is a revision,

Create a new Class named MyItems, then copy and paste this code in the class.

Public Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class

0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301756
Additionaly, delete this code in your main form...

Private Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301780
Then After doing all these things...

You can retrieve it like this in your dialog form.

If not Combobox1.SelectedItem is nothing then
   msgbox(ctype(Combobox1.SelectedItem,MyItems).ID)
End If
0
 

Author Comment

by:Sheritlw
ID: 24301991
Thank you very much.
That works great!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now