Solved

Add Specific Text with IDs to ComboBox

Posted on 2009-05-04
8
321 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 
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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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